I have problem with my c program.
char *p = Path[x]; if(p[strlen(p) - 1] != '\\')
char *FileName = p;
Path[x] = FileName; // add the directory to the list
As you see above Path is an array of string (char*) and the first item have primary directory path (the program is scanning files in root and sub directories).
The problem is when when p changes from ("j:\d") to ("j:\d\") (in if statement) .. Path[x] changes too exactly like p???
why when char pointer changes, it changes the other char pointer???
Edited 4-Feb-13 19:37pm
It is not clear what you are trying to do, but I think you oversimplified your code (also I believe strcpy(x, x) might be undefined behavior? or it just checks for a valid writeable buffer? or renews L1/L2/L3 cache?).
It looks like you are attempting to make sure that a directory spec has a terminating '\' character, then you append a filename to the directory spec. The 2 strcpy() calls don't do anything valid with the code as you present here. The strcat() calls do the heavy lifting for the 2 append operations. The 2 pointers 'p' and 'Filename' are pointers within the 'Path' buffer. If you append something to the end of either 'p' or 'Filename' you also append to 'Path'. They are all pointing within the same buffer space.
You're not creating a new string in your first line... you're assigning the pointer of the array
Path to the character pointer
p (they both point to the same memory address, I'm sure if you look at the addresses in a debugger you'll notice it's the same). If you want a new string that has the same value, you have to do a string copy (and a memory allocation for
Edited 4-Feb-13 20:04pm
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)