0

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.

2
Contributors
2
Replies
5
Views
6 Years
Discussion Span
Last Post by Don_k
0

Use a loop:

if (argc > 1) {
    int i;

    for (i = 1; i < argc; i++) {
        /* Open and read argv[i] */
    }
}

Edited by Narue: n/a

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.