From: Stef B. <st...@gm...> - 2009-12-27 00:06:52
|
Hello, I've a general question about the use of pointers. I'm using the function basename, and I've read that it gives back a pointer. but I can assign is to an array of char: #define MAX_PATHLEN 1024 static signed int testfunction(const char *path); { char testpath[MAX_PATHLEN]; fprintf(stdout, '"Value of path: %s.\n", path); testpath = basename(path); fprintf(stdout, "Value of testpath: %s.\n", testpath); return 0; } Well this is possible, but very confusing. Is this good C?? I've read that the function basename can alter the parameter, so it should be something like: basename(strdup(path)) Futher, the line with basename: basename is returning a pointer, so how can I assign the value of the pointer to the var testpath?? I've tried: testpath = *basename(path); but this gives anerror: error: invalid type argument of 'unary *' Now unary , the * is the indirection operator, not the unary operator, according http://www.cs.cf.ac.uk/Dave/C/node10.html#SECTION001000000000000000000 Can someone please shine some light here? I know that it's not fuse specific, and please do not start with RTFM or something of that sort, I've read enough and still don't get it. Thanks in advance, Stef |