I've been having a lot of problems trying to figure out how to use scanf()
. It seems to work fine with integers, being fairly straight forward scanf("%d", &i)
.
Where I am running into issues is using scanf()
in loops trying to read input. For example:
do {
printf("counter: %d: ", counter);
scanf("%c %c%d", &command, &prefix, &input);
} while (command != 'q');
When I enter in a validly structured input like
c P101
, it seems to loop again before prompting me. This seems to happen even with a single:scanf("%c", &c)
in a while loop. It'll do the loop twice before prompting me again. What is making it loop twice, and how do I stop it?
When I enter in less amount of input that programmatically wouldn't have another character or number such as
q
, pressing enter seems to prompt me to enter more. How do I getscanf()
to process both single and double character entries?