Hey guys,
I've wrote the following piece of code :
Code:
void procurastring2 (Ficheiro aux, char *string)
{
int flag=0;
char *buf;
int x;
int i;
int linha = 0;
printf("%s",aux->ficheiro);
x = open(aux->ficheiro,O_RDONLY);
read(x,buf,BUF_TAM_MAX);
linha=1;
if(buf[i]=='\n')
{
linha++;
}
else {
for(i=0; (buf[i]!= '\0') || (!flag) ;i++)
{
if(pref(string,buf+i)) {printf("%s foi encontrada na linha %d do ficheiro %s",string,linha,aux->ficheiro); flag=1;}
else {printf("A string não foi encontrada no ficheiro %s",aux->ficheiro); flag=1;}
}
close(x);
return 1;
}
}
I'm looking for the string 'portugal' inside my aux->ficheiro which is 'ola'.
Thing is, I wrote in my 'ola' file 'ola portugal'.
When doing this, seems like something writes on top and 'ola' has nothing in the end of the execution
Any help ?