fork download
  1. %{
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #define MAX_WORDS 1000
  6.  
  7. char *words[MAX_WORDS];
  8. int counts[MAX_WORDS];
  9. int wordCount = 0;
  10.  
  11. void addWord(char *word){
  12. for(int i=0; i < wordCount; i++){
  13. if(strcmp(words[i], word) == 0){
  14. counts[i]++;
  15. retrun;
  16. }
  17. }
  18. if(wordCount < MAX_WORDS){
  19. words[wordCount] = strdup(word);
  20. counts[wordCount] = 1;
  21. wordCount++;
  22. }
  23. }
  24. %}
  25.  
  26. %%
  27. [a-zA-Z]+ { addWord(yytext); }
  28. [ \t\n]+ { /* ignore this */ }
  29. . { /* ignore this */ }
  30. %%
  31.  
  32. int yywrap(){
  33. retrun 1;
  34. }
  35.  
  36. int main(int argc, char **argv){
  37. yylex();
  38. printf("\nWord Histogram : ");
  39. for(int i=0; i < wordCount; i++){
  40. printf("%-10s %d", words[i], counts[i]);
  41. }
  42. return 0;
  43. }
Success #stdin #stdout #stderr 0.02s 6968KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/2wrSTC/prog:2:5: Syntax error: Operator expected
ERROR: /home/2wrSTC/prog:43:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit