fork download
  1. %{
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int count = 0; // Counter to count occurrences
  6. char targetWord[100] = "word"; // Word to be counted, replace "word" with your target
  7.  
  8. %}
  9.  
  10. %%
  11. {targetWord} { count++; } // Increment count if target word matches
  12. .|\n { /* ignore other characters */ }
  13. %%
  14.  
  15. int main() {
  16. printf("Enter the word to search for: ");
  17. scanf("%s", targetWord); // Get target word from user
  18.  
  19. printf("Enter the sentence: ");
  20. yylex(); // Start lexical analysis
  21.  
  22. printf("Frequency of '%s': %d\n", targetWord, count);
  23. return 0;
  24. }
  25.  
  26. int yywrap() {
  27. return 1;
  28. }
Success #stdin #stdout #stderr 0.02s 6960KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/WnYf0s/prog:28:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit