I've got a loop that outputs a prompt and reads in a 'command' into a buffer:
while (strcmp (cmd_in, "exit") != 0) {
printf (">> ");
scanf ("%s", cmd_in);
}
However, if I type something like 'hello world', the prompt is output twice. I placed a printf in there to output cmd_in 'in-between' the loops to see it's value, like so:
while (strcmp (cmd_in, "exit") != 0) {
printf (">> ");
scanf ("%s", cmd_in);
printf ("%s\n", cmd_in);
}
Now if I type a space (ala 'hello world') then I see this:
>> hello world
hello
>>
world
>>
So it seems scanf takes spaces as deliminaters for new input? It's really annoying now because I can't find any way to surpress it.
Any ideas?