Created
July 23, 2016 01:03
-
-
Save parambirs/7833d98c182062d59a796543f59d27a1 to your computer and use it in GitHub Desktop.
Reading a character in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| char firstCh, secondCh; | |
| printf("Enter first character: "); | |
| scanf(" %c", &firstCh); // Note: a space before %c | |
| printf("Enter second character: "); | |
| scanf(" %c", &secondCh); | |
| // The following WON'T work as the newline entered as part of the first scanf would be consumed by the next scanf call: | |
| printf("Enter first character: "); | |
| scanf("%c", &firstCh); // Will not work correctly! | |
| printf("Enter second character: "); | |
| scanf("%c", &secondCh); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment