fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. int is_kw(char *b) {
  6. char *kw[] = {"int", "char", "if", "else", "while", "for"};
  7.  
  8. for (int i = 0; i < 6; i++)
  9. if (!strcmp(b, kw[i])) return 1;
  10.  
  11. return 0;
  12. }
  13.  
  14. int main() {
  15. FILE *f = fopen("input.txt", "r");
  16. char b[20], c;
  17.  
  18. while ((c = fgetc(f)) != EOF) {
  19. int i = 0;
  20.  
  21. while (isalnum(c) || c == '_') {
  22. b[i++] = c;
  23. c = fgetc(f);
  24. }
  25.  
  26. if (i > 0) {
  27. b[i] = '\0';
  28.  
  29. if (is_kw(b))
  30. printf("%s : Keyword\n", b);
  31. else if (isdigit(b[0]))
  32. printf("%s : Number\n", b);
  33. else
  34. printf("%s : Identifier\n", b);
  35. }
  36.  
  37. if (strchr("+-*/%=", c))
  38. printf("%c : Operator\n", c);
  39. }
  40.  
  41. fclose(f);
  42. return 0;
  43. }
Success #stdin #stdout #stderr 0.02s 3352KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/run-20112/prog:43:0: Syntax error: end_of_file_in_quasi_quotation
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit