Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Да се напише програма која на екран ќе го отпечати бројот на појавувања на даден збор составен само од цифри (зборот се чита од тастатура) во текстуална датотека со име dat.txt.
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #define MAX 101
- int findOccurance(char line[100],char word[10])
- {
- char *rez=strstr(line,word);
- if(rez==NULL)
- return 0;
- else{
- return 1+findOccurance(rez+strlen(word),word);
- }
- }
- int main()
- {
- FILE *inputFile=fopen("dat.txt" , "r");
- int counter=0;
- int i;
- char currLine[MAX];
- char word[10];
- scanf("%s",word);
- while(fgets(currLine,MAX,inputFile)!=NULL)
- {
- counter+=findOccurance(currLine,word);
- }
- printf("%d",counter);
- fclose(inputFile);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment