-
Comparing Files
ok my problem is this i have two files and i am comparing them like this.
for(a = 1;a <= 1; a = a + 1)
{
FILE*fp;
fp=fopen("finfile.txt","w");
if(word1[1]=word2[1])
{
fprintf(fp,"%s\n","fa");
}
if(word1[2]=word2[1])
{
fprintf(fp,"%s\n","fb");
}
//word1[3]=word2[1] (so on...)
fclose(fp);
i want word1 to compare to word2 now when i do this piece of code above it prints out to finfile which it shouldn't do because word1[1] is not the same as word2[1]. Can someone help me plz so that it will know that word1[1] isn't the same as word2[1]?
if you need any more peices of my code tell me and i shall post them for you.
thanks for whoever helps out :p
-
Try this algorithm.
-read one line at a time for both files via string
-compare the two lines via == operator
Kuphryn
-
didn't work
see in word1 (file name temp.txt) it only has 1 character "a" or "b" threw the whole alphabet then word2 (file name regfile.txt) is a whole bunch of characters like "hey" and i want it to see the letter "e" in word1 and then see the letter in word1 "e" is the same.
I tried-
the == didn't work
the string.
i think the problem is that i am comparing the character e to something with more then one letter and it sees hey not the letter e. im not sure ignor this i probibly dunno what im saying.
heres a bigger chunck of code to look over
string word1; //the alphabet in the file temp.txt.
char word2[24]; //the 1st in the file regfile.txt
char word3[24]; //the 2nd word in file regfile.txt
for(a = 1;a <= 1; a = a + 1)
{
FILE*fp;
fp=fopen("finfile.txt","w");
if(word1[1]==word3[1])
{
fprintf(fp,"%s\n","fa");
}
if(word1[2]==word2[1])
{
fprintf(fp,"%s\n","fb");
}
//word1[3]=word2[1] (so on...)
fclose(fp);
-
just to add im using borland c++ vrs 6