getchar.c 562 B

12345678910111213141516171819202122
  1. /* Get on character from stdin, and then print it back out.
  2. *
  3. * Same as getc(stdin).
  4. *
  5. * You have to press enter for the character to go through:
  6. * https://stackoverflow.com/questions/1798511/how-to-avoid-pressing-enter-with-getchar
  7. *
  8. * Used at:
  9. * https://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1/53937376#53937376
  10. */
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. int main(void) {
  14. char c;
  15. printf("enter a character: ");
  16. c = getchar();
  17. printf("you entered: %c\n", c);
  18. return EXIT_SUCCESS;
  19. }