I’m having a problem with chdir() in my C program – only when running on Linux (works fine on Mac). I’ve stripped down my code.
Something like this works fine:
chdir("/Documents");
but when I try to pass it as a variable it doesn’t want to work.
char *home_directory;
home_directory = malloc(80);
chdir(home_directory);
Home directory is read from a file elsewhere in my code, I can post how I’ve done that if needed.
Thanks.
Since you are reading
home_directoryfrom a file, have you forgotten to remove a trailing newline and any other spurious characters before you use it as a parameter tochdir?