ivana_andreevska

Untitled

May 21st, 2021
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. Да се напише програма која на екран ќе го отпечати бројот на појавувања на даден збор составен само од цифри (зборот се чита од тастатура) во текстуална датотека со име dat.txt.
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #define MAX 101
  7. int findOccurance(char line[100],char word[10])
  8. {
  9.     char *rez=strstr(line,word);
  10.     if(rez==NULL)
  11.         return 0;
  12.     else{
  13.         return 1+findOccurance(rez+strlen(word),word);
  14.     }
  15. }
  16.  
  17.  
  18. int main()
  19. {
  20.     FILE *inputFile=fopen("dat.txt" , "r");
  21.     int counter=0;
  22.     int i;
  23.  
  24.     char currLine[MAX];
  25.     char word[10];
  26.     scanf("%s",word);
  27.  
  28.     while(fgets(currLine,MAX,inputFile)!=NULL)
  29.     {
  30.             counter+=findOccurance(currLine,word);
  31.     }
  32.     printf("%d",counter);
  33.     fclose(inputFile);
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment