06-03-2009
How to get the sizeof char pointer
The below code throws the error, since the size of x = 19 is not passed to the cstrCopy function.
using namespace std;
static void cstrCopy(char *x, const char*y);
int main ()
{
char x[19];
const string y = "UNIX FORUM";
cstrCopy(x,y.c_str());
return 0;
}
void cstrCopy(char *x, const char *y)
{
if(strlen(y) >= sizeof(x)) {
throw errorException;
}
strncpy(x, y, sizeof(x));
}
How to pass the size of char pointer to a function.?
Please help.
10 More Discussions You Might Find Interesting
1. Programming
we know that sizeof never returns zero when used with structure
then why in this case it is returning zero
struct foo
{
char c;
};
void main()
{
struct foo f;
cout<<sizeof(f);
}
i am working on solaris 5.8
isn't the above function should return the size of empty structure (7 Replies)
Discussion started by: ramneek
7 Replies
2. Programming
Hi,
char *s="yamaha";
cout<<s<<endl;
int *p;
int i=10;
p=&i;
cout<<p<<endl;
1) For the 1st "cout" we will get "yamaha" as output. That is we are getting "content of the address" for cout<<s.
2) But for integer "cout<<p" we are getting the "address only".
Please clarify how we are... (2 Replies)
Discussion started by: sweta
2 Replies
3. Programming
Hello,
I'm trying to write a method which will return the extension of a file given the file's name, e.g. test.txt should return txt. I'm using C so am limited to char pointers and arrays. Here is the code as I have it:
char* getext(char *file)
{
char *extension;
int i, j;... (5 Replies)
Discussion started by: pallak7
5 Replies
4. Programming
If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it:
(1) one is to pass a pointer-to-pointer parameter, like:
int my_malloc(int size, char **pmem)
{
*pmem=(char *)malloc(size);
if(*pmem==NULL)... (11 Replies)
Discussion started by: aaronwong
11 Replies
5. Programming
Hi All,
is it possible to find out the size of an array of structures ( without using 'sizeof' operator). The condition is we have the array of structure instant but we are not aware of the elements inside the structure.
Can someone help me out?
Thanks in advance. (18 Replies)
Discussion started by: rvan
18 Replies
6. Programming
Hi,
There are some bewildering sizeof() questions I have in my mind. Could anyone shed some light on this?
int main() {
printf("%d\n", sizeof(main)); // Ans: 1
}
That is, the sizeof() a function identifier though it is treated internally as a pointer gives 1 byte always, why?
... (5 Replies)
Discussion started by: royalibrahim
5 Replies
7. Programming
Hi,
I have defined the class and call the sizeof(object to class) to get the size.
# include <iostream>
# include <iomanip>
using namespace std;
class sample
{
private:
int i;
float j;
char k;
public:
sample()
{
} (2 Replies)
Discussion started by: ramkrix
2 Replies
8. Programming
i have an array like
#define NUM 8
....
new_socket_fd = accept(socket_fd, (struct sockaddr *) &cli_addr, &client_length);
char *items = {"one", "two", "three", "four", "five", "six", "seven", "eight"};
char *item_name_length = {"3", "3", "5", "4", "4", "3", "5", "5"};
... (1 Reply)
Discussion started by: omega666
1 Replies
9. Programming
Ignoring other considerations for a moment and in general ...
Would there be a difference in result (dot oh or execution) of:
A.
strncpy( a, b, sizeof(a) );
vs.
B.
c = sizeof(a);
strncpy( a, b, c );
My general understanding is (at least I think my understanding is) that... (10 Replies)
Discussion started by: GSalisbury
10 Replies
10. Programming
I am passing a char* to the function "reverse" and when I execute it with gdb I get:
Program received signal SIGSEGV, Segmentation fault.
0x000000000040083b in reverse (s=0x400b2b "hello") at pointersExample.c:72
72 *q = *p;
Attached is the source code.
I do not understand why... (9 Replies)
Discussion started by: jose_spain
9 Replies
LEARN ABOUT DEBIAN
rudecgi
rudecgi(3) User Manuals rudecgi(3)
NAME
rudecgi - access formdata in CGI applications
SYNOPSIS
#include <rude/cgi.h>
rude::CGI CGI();
static void finish();
static const char *version();
static void setPathDelimiter(char delimiter);
static void addPathMapName(const char *pathname );
static void setPathMapVoid(const char *emptyname);
static void parsePathMap(bool shouldParse);
static void parsePath(bool shouldParse);
static void parseCookies(bool shouldParse);
static void maxPostLength(long bytes);
void setCaseSensitive(bool isCaseSensitive);
int numValues() const;
int numValues(const char *fieldname) const;
const char *fieldnameAt(int position) const;
bool exists(const char *fieldname) const;
bool isFile(int index) const;
bool isFile(const char *fieldname) const;
bool isFile(const char *fieldname, int position);
const char *datasource(int index) const;
const char *datasource(const char *fieldname) const;
const char *datasource(const char *fieldname, int position) const;
const char * operator[](const char *fieldname);
const char * operator[](int x);
const char *value(int index) const;
const char *value(const char *fieldname) const;
const char *value(const char *fieldname, int position) const;
const char *length(int index) const;
const char *length(const char *fieldname) const;
const char *length(const char *fieldname, int position) const;
const char *contenttype(int index) const;
const char *contenttype(const char *fieldname) const;
const char *contenttype(const char *fieldname, int position) const;
const char *filename(int index) const;
const char *filename(const char *fieldname) const;
const char *filename(const char *fieldname, int position) const;
const char *filepath(int index) const;
const char *filepath(const char *fieldname) const;
const char *filepath(const char *fieldname, int position) const;
std::ostream& operator<<(std::ostream& os,const CGI& cgi);
DESCRIPTION
The RudeCGI library is used to access formdata within C++ CGI applications.
EXAMPLES
Examples, how-to's and tutorials can also be found at the rudeserver.com website
Basic Usage
#include <rude/cgi.h> #include <iostream>
using namespace std; using namespace rude;
int main(void) {
// Obtain the cgi instance
//
CGI cgi;
// Print out standard CGI HTTP Response header
//
cout << "Content-Type: text/html0;
// Print out HTML
//
cout << "<html><body>"
<< "You selected the color: " ;
// use the cgi object to obtain form data
//
cout << cgi["color"];
cout << "</body></html>";
return 0; }
SEE ALSO
rudeconfig(3), rudedatabase(3), rudesocket(3), rudesession(3)
REPORTING PROBLEMS
Before reporting a problem, please check the rudeserver.com web site to verify that you have the latest version of rudecgi; otherwise,
obtain the latest version and see if the problem still exists. Please read the FAQ at:
http://www.rudeserver.com/
before asking for help. Send questions and/or comments to matt@rudeserver.com
AUTHORS
Copyright (C) 2000 Matthew Flood (matt@rudeserver.com)
This software is provided "as-is," without any express or implied warranty. In no event will the authors be held liable for any damages
arising from the use of this software. See the distribution directory with respect to requirements governing redistribution. Thanks to
all the people who reported problems and suggested various improvements in rudecgi; who are too numerous to cite here.
Version 4.1.1 January 11, 2006 rudecgi(3)