Problem when reading input in C
- by gcx
I've made a Linked List. Its elements keep both previous and next items' address. It gets commands from an input file. It detects the command and uses the following statement as a parameter. (text: add_to_front john - means: add_to_front(john))
Code: http://pastebin.com/KcAm1y3L
When I try to give the commands from an input file it gives me same output over and over. However, if I write inputs in main() manually, it works.
For ex input file:
add_to_front john
add_to_back jane
add_to_back jane
print
(unfortunately) the output is:
>add_to_front john
>add_to_back jane
>add_to_back jane
>print
jane
jane
jane
Although, if I write
add_to_front(john);
add_to_back(jane);
add_to_back(jane);
print();
instead of this command check:
while (scanf("%s",command)!=EOF)
{
if (strcmp(command,"add_to_front")==0)
{
gets(parameter);
add_to_front(parameter);
}
else if (strcmp(command,"add_to_back")==0)
{
gets(parameter);
add_to_back(parameter);
}
else if (strcmp(command,"remove_from_back")==0)
remove_from_back(parameter);
...
printf(" HUH?\n");
}
}
in main() it gives the correct output.
I know it's a lot to ask but this thing is bothering me for 2 days. What do you think i'm doing wrong?