processing more than one file at a time

This is a discussion on processing more than one file at a time within the C Programming forums, part of the General Programming Boards category; Hi, I am writing a utility that processes a system file , but this file exists in all drives. C:\file1 ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    130

    processing more than one file at a time

    Hi,

    I am writing a utility that processes a system file , but this file exists in all drives.

    C:\file1
    D:\file1
    E:\file1

    My question: how can I process all files at the same time since when I want to run my utility I pass the path for one file

    Code:
    f=fopen("C:\\file1","r");
    Note: The system file may contains different content according to the drive, but it has the same name for all drives

    Thankx

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You can't open multiple files with a single fopen all. You will need to call it multiple times. Fill an array with your file and location, and modify it before each call to change the drive letter.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    130
    Please, explain more

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Fill an array with your path. That is, instead of passing a string literal, pass an array. Now change the C to a D to an E to ... each time you call the function.
    Code:
    char filename[] = "c:\\foo.bar";
    size_t x;
    FILE *fp;
    
    for( x = 0; x < numdrives; x++ )
    {
        fp = fopen( filename, "r" );
        if( fp )
        {
            process_file( fp );
            fclose( fp );
        }
        filename[0]++;
    }

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    And run your program as
    myprog C:\file1 D:\file1 E:\file1

    Just have a loop to open and close each argv[n] in turn.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  4. File processing program not workin...
    By Nutshell in forum C Programming
    Replies: 6
    Last Post: 01-30-2002, 10:25 PM

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