fork download
  1. #include <stdio.h>
  2.  
  3. void main()
  4. {
  5. int count = 0, i, times = 0, t, h, e, space;
  6. char string[100];
  7.  
  8. puts("Enter a string:");
  9. gets(string);
  10. /* Traverse the string to count the number of characters */
  11. while (string[count] != '\0')
  12. {
  13. count++;
  14. }
  15. /* Finding the frequency of the word 'the' */
  16. for (i = 0; i <= count - 3; i++)
  17. {
  18. t =(string[i] == 't' || string[i] == 'T');
  19. h =(string[i + 1] == 'h' || string[i + 1] == 'H');
  20. e =(string[i + 2] == 'e'|| string[i + 2] == 'E');
  21. space =(string[i + 3] == ' ' || string[i + 3] == '\0');
  22. if ((t && h && e && space) == 1)
  23. times++;
  24. }
  25. printf("Frequency of the word 'the' is %d\n", times);
  26. }
Success #stdin #stdout 0s 5300KB
stdin
Standard input is empty
stdout
Enter a string:
Frequency of the word 'the' is 0