0

I am trying to get my while loop to break whenever "action" equals "CE".

while(1){
    scanf("%s\n", action);
    if(strcmp(action, "CE")==0){
      break;
    ...
    }

However, when I input "CE", my loop doesn't break but instead runs through my while loop and then breaks after asking me for an "action" input again.

Why is it doing this and how to I get it to break immediately after the scanf statement?

  • 1
    Try with the `\n` removed from the `scanf`. If that still doesn't work then please provide complete code as a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) as well the exact input, expected result and actual result. (Not a description of the input but the actual run log). – kaylum Apr 09 '21 at 21:12
  • @kaylum removing the \n fixed it. Thank you very much! – Mad Dog Apr 09 '21 at 21:15

0 Answers0