I need to do a simple search engine. Just open arquivo.txt
, search for a word desired by the user, check how many times a word appears in the file and whether it exists in the file. But this is giving an error that I did not identify the origin, similar to the absence of &
. Here is my code:
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#define max 500
int main(){
char pprocurada[100];
char *buff[500];
int contpp=0;
FILE *arq;
arq=fopen("C:\Users\jvict_000\Desktop\JoaoVictorF\FaroesteCaboclo.txt", "r");
if(arq==NULL)
printf("n%co foi possivel abrir o arquivo\n",132);
printf("Digite a palavra a ser pesquisada\n");
fflush(stdin);
gets(pprocurada);
fflush(stdin);
fgets(*buff,max,arq);
while (!feof(arq)) {
if(contpp==0) {
strtok(*buff," ");
if(strcmp(pprocurada,*buff)==0)
contpp++;
} else {
strtok(NULL," ");
if(strcmp(pprocurada,*buff)==0)
contpp++;
}
fflush(stdin);
fgets(*buff,max,arq);
}
fclose(arq);
if(contpp!=0)
printf("Pesquisa terminada, a palavra %s foi encontrada: %d vezes",pprocurada,contpp);
else {
printf("A palavra %s n%co foi encontrada no arquivo",pprocurada,132);
}
return 0;
}