I'm currently building my own shell. I managed to make ls function using scanf() and now I'm on cd. But I realized that cd has space between cd and file so I changed scanf() to fgets().
The space problem has been solved but another problem came out. Even though I typed correctly, the program won't work.
char command[MAX_LEN];
int result = 1;
char *pwd[MAX_LEN];
do {
printf("%s > ", getcwd(pwd, 100));
fgets(command, 100, stdin);
if(!strcmp("cd", command))
change_dir();
if(!strcmp("ls", command))
list_dir();
} while(strcmp("exit", command));
return 0;
What is wrong with my code? Can you please tell me why it's happening?