How to break out of while loop in C

Depending on what you are trying to do, you might want %c instead of %s in the scanf format. That will get you a single char. Then you can compare to “q” like this: command[0]=='q'.

But you might want to take in a multi-character command, in which case, strcmp and a longer buffer are what you want.

Leave a Comment