Hi I am a beginner in C. I am working on a program that asks to search words from one file whether they exist in other or not. Here is the code.
The problem seems to be that when the first word is extracted from one file and searched and compared through the whole other file ,the next time outer loop starts the inner loop exits because dt_val is still seems be be EOF . After the loop I do assign it to 0 but it does'nt help the search of the complete first file in other.
Please help
Code:
int main(void)
{
FILE* tx;
FILE* dt;
int dt_val=0;
int tx_val=0;
int c=0;
char buff_tx[20];
char buff_dt[20];
tx= fopen("C:\\newdt1.txt","r");
dt= fopen("C:\\newdt.txt","r");
if((tx==NULL)&&(dt==NULL))
printf("Both Failed\n");
else
{
while(tx_val!=EOF)
{
tx_val=fscanf(tx,"%s",buff_tx);
while(dt_val!= EOF)
{
dt_val=fscanf(dt,"%s",buff_dt);
if(strcmp(buff_dt,buff_tx)==0)
c++;
}
dt_val=0
if(c==0)
printf("It does not exists\n");
else
printf("Does\n");
c=0;
}
}
fclose(tx);
fclose(dt);
return 0;
}