I have these variables set in my debugger:
//Debugger values not code
relative_path = “./bin/Debug”
strlen(relative_path)=11
relative_path[11] = 0 ‘\000’ //As shown in Eclipse debugger
In my code I then do:
//**My Code**
struct dirs_later {
const char *findme;
struct dirent *dptr;
struct stat this_lstat;
char *relative_path;
const char *type_str;
DIR * dir;
};
....
struct dirs_later *new_dir = malloc(sizeof(struct dirs_later*));
...
char *relative_path2 = strdup(relative_path);
if (NULL != new_dir) {
new_dir->findme = findme;
new_dir->dptr = dptr;
new_dir->this_lstat = *this_lstat;
new_dir->relative_path = relative_path2;
new_dir->type_str = type_str;
}
but then the debugger shows after new_dir->relative_path = relative_path2. Then in the debugger:
//Debugger values not code
relative_path2 = “&\275\001” and
strlen(relative_path2) =3
I also tried this in my code instead:
//**My Code**
char *relative_path2 = malloc(strlen(relative_path) + 1 * sizeof(char));
//check for NULL
strcpy(relative_path2, relative_path);
and I get the same result
Should the line
be
as you want to create the space on the heap for the structure, not just a pointer.