Skip to content

Instantly share code, notes, and snippets.

@parambirs
Created July 23, 2016 01:03
Show Gist options
  • Select an option

  • Save parambirs/7833d98c182062d59a796543f59d27a1 to your computer and use it in GitHub Desktop.

Select an option

Save parambirs/7833d98c182062d59a796543f59d27a1 to your computer and use it in GitHub Desktop.
Reading a character in C
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