fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. int isOperator(char c) {
  6. return (c == '+' || c == '-' || c == '*' || c == '/' ||
  7. c == '>' || c == '<' || c == '=' || c == '!');
  8. }
  9.  
  10. int main() {
  11. char input[200];
  12. int i = 0;
  13.  
  14. printf("Enter a simple C code snippet: ");
  15. fgets(input, sizeof(input), stdin);
  16.  
  17. printf("Tokens Found:\n");
  18.  
  19. while (input[i] != '\0') {
  20.  
  21. if (input[i] == ' ' || input[i] == '\n') {
  22. i++;
  23. continue;
  24. }
  25.  
  26. if (isOperator(input[i])) {
  27.  
  28. if ((input[i] == '>' && input[i+1] == '=') ||
  29. (input[i] == '<' && input[i+1] == '=') ||
  30. (input[i] == '=' && input[i+1] == '=') ||
  31. (input[i] == '!' && input[i+1] == '=') ||
  32. (input[i] == '+' && input[i+1] == '=') ||
  33. (input[i] == '-' && input[i+1] == '=')) {
  34.  
  35. printf("OPERATOR: %c%c\n", input[i], input[i+1]);
  36. i += 2;
  37. }
  38. else {
  39. printf("OPERATOR: %c\n", input[i]);
  40. i++;
  41. }
  42. }
  43. else {
  44. i++;
  45. }
  46. }
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 5324KB
stdin
int a +=b
stdout
Enter a simple C code snippet: Tokens Found:
OPERATOR: +=