getc_unget.c 219 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. exit(EXIT_SUCCESS);
  9. }
  10. printf("failed :( %c\n", c);
  11. exit(EXIT_FAILURE);
  12. }