Thread: Read Each Line of File as Array Record

  1. #1
    Registered User
    Join Date
    Feb 2010
    Location
    UK
    Posts
    8

    Read Each Line of File as Array Record

    Hi All,

    Im having a lot of problems trying to work out a piece of code for a small program.

    What im trying to do is to write a function which reads each line of a text file called 'FILE1' into a new record in an array. I then want to do the same with another text file called 'FILE2'. This should allow me to compare each records of 'ARRAY1' to each record of 'ARRAY2' and report if they are the same.

    e.g.

    FILE 1 / ARRAY 1 FILE 2 / ARRAY 2 MATCH?
    AAAA DDDD Yes (As D is in both)
    BBBB EEEE NO
    CCCC FFFF NO
    DDDD GGGG NO


    Im sorry to put such a simple diagram in but couldn't think how else to explain it.

    Thank you so much for any help, ideas, thoughts or code,
    Leo2010

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    Reading a line into an array is easy to do with fgets. How efficient you then can compare the two files depends on whether or not they are sorted in some way like in your example.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Location
    UK
    Posts
    8
    Hi, I've tried experimenting with those but not managed to get them to work at all, any other ideas? or examples of what i may be doing wrong in your experience?

    Thanks

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    It would be a lot easier if you would just show what you've attempted so we can see what you did wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. read from file into Array
    By tinus in forum C Programming
    Replies: 11
    Last Post: 04-13-2007, 07:11 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

Tags for this Thread