954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C: read/write more than one file?

Hey guys using Linux(C) using POSIX API system calls read,write, open etc. I can open,read,write to a file and copy its contents to an output file. How would I go about copying more than one file to an output file using related system calls only.

I currently have:

filein = open(argv[1],O_RDONLY,0);


to open one file.(which is argv1 but I'd like to know how to do argv2 and argv3 etc.)

I tried :

j=0; filein = open(argv[j],)_RDONLY,0);

but that prints out contents of argv0 into my outputfile.

I am stuck on the next stage to do more than one file. (I also have an EOF loop so after 1 file it exits-How would I make this continue for the next file).

Please could you help me with how to approach the next stage thanks.

Don_k
Newbie Poster
20 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

Use a loop:

if (argc > 1) {
    int i;

    for (i = 1; i < argc; i++) {
        /* Open and read argv[i] */
    }
}
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Thank you for your reply and help, I will try this out now

Don_k
Newbie Poster
20 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You