copying to multiple destination

This is a discussion on copying to multiple destination within the Linux Programming forums, part of the Platform Specific Boards category; Any idea how can I copy file to multiple destination, like placing a file to multiple directories. Tahnks...

  1. #1
    Unregistered
    Guest

    copying to multiple destination

    Any idea how can I copy file to multiple destination, like placing a file to multiple directories.

    Tahnks

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    How about something like this
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
        FILE    *ifp, *ofp;
        int     i, c;
    
        if (argc < 3)
        {
            printf("Args needed\nEG: mycopy source target1 target2 target3 ...");
            return(EXIT_FAILURE);
        }
    
        if ((ifp = fopen(argv[1], "rb")) == NULL)
        {
            perror(argv[1]);
            return(EXIT_FAILURE);
        }
    
        for (i = 2; i < argc; i++)
        {
            printf("copying to %s\n", argv[i]);
            if ((ofp = fopen(argv[i], "wb")) == NULL)
            {
                perror(argv[i]);
                continue;
            }
    
            while ((c = fgetc(ifp)) != EOF && fputc(c, ofp) != EOF)
                ;
            if (ferror(ofp)) perror(argv[i]);
            if (ferror(ifp) || !feof(ifp)) perror(argv[1]);
            fclose(ofp);
            rewind(ifp);
        }
    
        fclose(ifp);
    
        return(EXIT_SUCCESS);
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 06-08-2009, 03:03 PM
  2. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  3. Linker errors - Multiple Source files
    By nkhambal in forum C Programming
    Replies: 3
    Last Post: 04-24-2005, 02:41 AM
  4. copy multiple files to a destination file
    By Bones in forum C++ Programming
    Replies: 2
    Last Post: 10-02-2003, 10:47 AM
  5. Copying info from multiple sources
    By Prog.Patterson in forum Windows Programming
    Replies: 5
    Last Post: 04-29-2002, 11:42 AM

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