#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include<conio.h>
int wc(char* file_path, char* word){
FILE *fp;
int count = 0;
int ch, len;
if(NULL==(fp=fopen(file_path, "r")))
return -1;
len = strlen(word);
for(;;){
int i;
if(EOF==(ch=fgetc(fp))) break;
if((char)ch != *word) continue;
for(i=1;i<len;++i){
if(EOF==(ch = fgetc(fp))) ;
if((char)ch != word[i]){
fseek(fp, 1-i, SEEK_CUR);
goto next;
}
}
++count;
next: ;
}
end:
fclose(fp);
return count;
}
int main(){//testestest : count 2
while(1)
{
int i=0;
char key[100]; // the string I am searching for
char c;
printf("\nEnter Word for search....");
gets(key);
int len=strlen(key);
for(i=0;i<len;i++)
{
if(key[i]==' ')
{
printf("Sorry Space are note allowd...\n");
}
}
int wordcount = 0;
wordcount = wc("text.txt", key);
printf("-----------------------------------------------\n\n");
printf(" This Word rapeated { %d } time\n\n",wordcount);
printf("-----------------------------------------------\n\n");
}
getch();
return 0;
}
#include <string.h>
#include <stdlib.h>
#include<conio.h>
int wc(char* file_path, char* word){
FILE *fp;
int count = 0;
int ch, len;
if(NULL==(fp=fopen(file_path, "r")))
return -1;
len = strlen(word);
for(;;){
int i;
if(EOF==(ch=fgetc(fp))) break;
if((char)ch != *word) continue;
for(i=1;i<len;++i){
if(EOF==(ch = fgetc(fp))) ;
if((char)ch != word[i]){
fseek(fp, 1-i, SEEK_CUR);
goto next;
}
}
++count;
next: ;
}
end:
fclose(fp);
return count;
}
int main(){//testestest : count 2
while(1)
{
int i=0;
char key[100]; // the string I am searching for
char c;
printf("\nEnter Word for search....");
gets(key);
int len=strlen(key);
for(i=0;i<len;i++)
{
if(key[i]==' ')
{
printf("Sorry Space are note allowd...\n");
}
}
int wordcount = 0;
wordcount = wc("text.txt", key);
printf("-----------------------------------------------\n\n");
printf(" This Word rapeated { %d } time\n\n",wordcount);
printf("-----------------------------------------------\n\n");
}
getch();
return 0;
}