getc_unget.c 221 B

12345678910111213
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(void) {
  4. ungetc('h', stdin);
  5. char c;
  6. if ((c = getchar()) == 'h') {
  7. printf("Worked!\n");
  8. return EXIT_SUCCESS;
  9. }
  10. printf("failed :( %c\n", c);
  11. return EXIT_FAILURE;
  12. }