
Untitled
By: a guest on
Apr 25th, 2012 | syntax:
None | size: 0.80 KB | hits: 10 | expires: Never
Unable to copy string
//**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;
}
//**My Code**
char *relative_path2 = malloc(strlen(relative_path) + 1 * sizeof(char));
//check for NULL
strcpy(relative_path2, relative_path);
struct dirs_later *new_dir = malloc(sizeof(struct dirs_later*));
struct dirs_later *new_dir = malloc(sizeof(struct dirs_later));