Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int Search(char line[], char word[])
- {
- char *p;
- int count = 0;
- //start = line;
- while(1){
- p = strstr(line, word);
- if(p == NULL)break;
- ++count;
- line = p + strlen(word);
- }
- return count;
- }
- int main(){
- int nf = 0, nw = 0, nd = 0, ni = 0;
- char s[100];
- FILE *fp;
- fp = fopen("f1.txt", "r");
- while(fgets(s, 100, fp)){
- nf += Search(s, "for");
- nw += Search(s, "while");
- nd += Search(s, "do");
- ni += Search(s, "if");
- }
- fclose(fp);
- printf("V file f1 vstretilos:n");
- printf("for %d raza nwhile %d raza ndo %d raza nif %d razan", nf, nw, nd, ni);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement