fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int counts(char * s, const char * m)
  5. {
  6. const char * delimeters = " ,.\t:;\"\'"; // Все, что разделяет слова :)
  7. int cnt = 0;
  8. for(s = strtok(s,delimeters);s;s = strtok(0,delimeters))
  9. if (!strcmp(s,m)) ++cnt;
  10. return cnt;
  11. }
  12.  
  13.  
  14. int main(int argc, const char * argv[])
  15. {
  16. char s[] = "Tom, Tom, and Tom went to the river.";
  17.  
  18. printf("There are %d \"Tom\" in string\n",counts(s,"Tom"));
  19.  
  20. }
  21.  
Success #stdin #stdout 0s 4864KB
stdin
Standard input is empty
stdout
There are 3 "Tom" in string