Advertisement
Guest User

Untitled

a guest
May 26th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int Search(char line[], char word[])
  5. {
  6. char *p;
  7. int count = 0;
  8. //start = line;
  9. while(1){
  10. p = strstr(line, word);
  11. if(p == NULL)break;
  12.  
  13. ++count;
  14. line = p + strlen(word);
  15. }
  16. return count;
  17. }
  18.  
  19. int main(){
  20.  
  21. int nf = 0, nw = 0, nd = 0, ni = 0;
  22. char s[100];
  23. FILE *fp;
  24. fp = fopen("f1.txt", "r");
  25. while(fgets(s, 100, fp)){
  26. nf += Search(s, "for");
  27. nw += Search(s, "while");
  28. nd += Search(s, "do");
  29. ni += Search(s, "if");
  30. }
  31. fclose(fp);
  32. printf("V file f1 vstretilos:n");
  33. printf("for %d raza nwhile %d raza ndo %d raza nif %d razan", nf, nw, nd, ni);
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement