#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<string.h>
int main()
{
char temporaryPath[50];
fgets(temporaryPath, sizeof(temporaryPath), stdin);
if(chdir(temporaryPath) == -1)
printf("Failed to change directory\n");
getcwd(temporaryPath, 1000);
printf("%s> ", temporaryPath);
}
I have been searching a lot about changing directories but I haven't been able to figure out why chdir() is failing in this case. If I use fgets() instead of hard coding the temporaryPath array, chdir() fails to change directory. Why is that and what could be done to fix it?
Thank you very much :)