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.

Use a loop:

if (argc > 1) {
    int i;

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.