Hello,
I need to write a function as follows:
//return a list of all the names d has
char** ls(directory* dir);
struct directory{
char* name;
int num_of_files;
struct directory *next;
}
My problem is that name could be of any size and d can be of any size and I can't get the dynamic allocation to work for **char. Here is an attempt:
ret = (char**)malloc(sizeof(dir->num_of_files)*sizeof(char*));
for(i=0; i<dir->num_of_files; i++){
ret[i] = malloc(sizeof(char)*sizeof(dir->name));
ret[i] = dir->name;
dir->files = dir->files->next;
}
Hope someone can straighten this out for me and write out how this should be done. Send an email to [email protected]
Thanks