Comparing Files

This is a discussion on Comparing Files within the C++ Programming forums, part of the General Programming Boards category; ok my problem is this i have two files and i am comparing them like this. for(a = 1;a <= ...

  1. #1
    Registered User snowy101's Avatar
    Join Date
    May 2002
    Posts
    22

    Post 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

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Try this algorithm.

    -read one line at a time for both files via string
    -compare the two lines via == operator

    Kuphryn

  3. #3
    Unregistered
    Guest

    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);

  4. #4
    Registered User snowy101's Avatar
    Join Date
    May 2002
    Posts
    22
    just to add im using borland c++ vrs 6
    Attached Images Attached Images  

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error opening files in a different dir
    By Ozzie in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2008, 06:55 AM
  2. Program Deployment and DLL/OCX Files?
    By dfghjk in forum C++ Programming
    Replies: 5
    Last Post: 06-16-2008, 02:47 AM
  3. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 01:41 PM
  4. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  5. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21