Wednesday, December 28, 2022

Using scanf to get user input from console

In C, you can use scanf to get character input from console. However, if you do it multiple times, you will realize that pressing enter after the first scanf affects the next scanf call. This happens when you have a space after your prompt, e.g. printf("Choice: "); char c; scanf("%c"). Either don't put a space at the end of printf or use a space in scanf like so: scanf(" %c")