Thread: Comparing Files.

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    5

    Comparing Files.

    Hey guys,

    I have 30 files full of mac addresses. What do you think would be the best way to compare all these files and output the mac addresses that show up in all 30 files to a new file. Is there a compare function? Should I read them into arrays and compare them? Any ideas would help out, I am a newbie to C but understand the basics. Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    http://cboard.cprogramming.com/showthread.php?t=56543
    Or is this a slightly different problem?

    If the files are text files, one MAC address per line, then I can do this using a 2-line AWK program
    Code:
    { count[$1]++ }
    END { for ( i in count ) if ( count[i] == 30 ) print i
    Save that as a file called program.

    Then do
    Code:
    awk -f program mac_file*.txt
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    5
    Yes it is the same question, I forgot I asked here already. Thanks for your reply. I like your way of doing it.

  4. #4
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    I would suggest separating each MAC address by strings, and using the function strcmp() to compare. If you dont know how to do this specifically, the FAQ should have all the info you need. If it doesn't, post again and I will do what I can

    [edit]
    Ahhh! Curses!
    [/edit]

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, 02: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