Hi there, i'm trying to make a program which translates a word from one language to another, using files (one file for each language)
i'm using fgets, to read a line from the file and then comparing it to what the user entered, and strcomp() to see if the words match, but for some reason, it doesn't work
Here is the code
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main ()
{ int i=0;
int bandera=0;
int repite=0;
char frase [100];
char auxiliar [20];
char auxiliar2[20];
int opcion=0;
do{
FILE * pfile;
FILE * pfile2;
pfile = fopen ("quechua.txt" , "r");
pfile2 = fopen ("espanol.txt" , "r");
if (pfile == NULL) perror ("Error opening file");
else if (pfile2 == NULL) perror ("Error opening file");
else {
cout<<"Digite palabra a traducir [en espanol]"<<endl;
cin>>frase;
while (!feof(pfile))
{
fgets (auxiliar,20,pfile2);
fgets(auxiliar2,20,pfile);
if (strcmp(frase,auxiliar)==0)
{
puts(auxiliar2);
bandera=1;
}
}
if (bandera==0)
{
cout<<"no se encontro la palabra buscada"<<endl;
}
fclose(pfile);
fclose(pfile2);
cout<<"Desea traducir otra cosa \n1-Si \n2-No"<<endl;
cin>>repite;}
}while (repite==1);
}
i would also like to know if there is a better way to accomplish this task, any help would be greatly appreciated :)