C – trying to read a single char from stdin (and failing) w/ scanf / getchar

You need a space between scanf(" and the %c for it to work correctly:

scanf(" %c", &choice);

And you also need to use &choice, not choice!

EDIT: While you’re at it, you might want to look into do while() for that loop (unless the professor specifically said to use a break) – do while works great when validating user input!

Leave a Comment