getc_unget.c 246 B

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