fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int num;
  5. char c = 'a';
  6.  
  7. while(c != '?')
  8. {
  9. if (scanf("%d", &num) == 1)
  10. {
  11. printf("Okay you got an integer with value %d\n", num);
  12. }
  13. else if (scanf("%c", &c) == 1)
  14. {
  15. // Okay you got a char
  16. if (c == '?')
  17. {
  18. printf("You got your ? Program will end\n");
  19. }
  20. else
  21. {
  22. printf("Some other char, i.e. %c\n", c);
  23. }
  24. }
  25. else
  26. {
  27. // Input error that can't be recovered
  28. exit(1);
  29. }
  30. }
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 5292KB
stdin
10 -80 hi 77?
stdout
Okay you got an integer with value 10
Okay you got an integer with value -80
Some other char, i.e. h
Some other char, i.e. i
Okay you got an integer with value 77
You got your ? Program will end