nogo.c 777 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* nogo.c -- will this work? */
  2. #include <stdio.h>
  3. #define ANSWER "Grant"
  4. #define SIZE 40
  5. char * s_gets(char * st, int n);
  6. int main(void)
  7. {
  8. char try[SIZE];
  9. puts("Who is buried in Grant's tomb?");
  10. s_gets(try, SIZE);
  11. while (try != ANSWER)
  12. {
  13. puts("No, that's wrong. Try again.");
  14. s_gets(try, SIZE);
  15. }
  16. puts("That's right!");
  17. return 0;
  18. }
  19. char * s_gets(char * st, int n)
  20. {
  21. char * ret_val;
  22. int i = 0;
  23. ret_val = fgets(st, n, stdin);
  24. if (ret_val)
  25. {
  26. while (st[i] != '\n' && st[i] != '\0')
  27. i++;
  28. if (st[i] == '\n')
  29. st[i] = '\0';
  30. else // must have words[i] == '\0'
  31. while (getchar() != '\n')
  32. continue;
  33. }
  34. return ret_val;
  35. }