Handling user input in C
- by Stuart
In C, I am writing a program which is taking in user input than comparing it to see which output it should use. I am finding it problomatic and was wondering if someone could give me a hand. So far I have:
while(cmd[0] != EOF){
fgets(cmd, sizeof(cmd), stdin); /** Takes in user input and stores it in cmd **/
if(cmd[0] == '\n')
printf("%s> ", cwd);
else if(strcmp(cmd, "ls") == 0)
printf("I will list everything");
}
Any ideas?
Basically it is just ignoring any user input when there is some.
P.S. The variable cwd is just a string.