Handling user input in C
Posted
by
Stuart
on Stack Overflow
See other posts from Stack Overflow
or by Stuart
Published on 2011-02-13T23:18:28Z
Indexed on
2011/02/13
23:25 UTC
Read the original article
Hit count: 225
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.
© Stack Overflow or respective owner