Hey forum,

Having a little trouble here with a C program I'm writing.

I want to take a string as input, eg:
./my_program -arg1 -arg2 -arg3 ... -arg 29

and pass it into an execlp function (with the arguments). I Need it to be hable to handle any amount of arguments.

What i'm doing so far is this:
Code:
fgets(buffer, 2048, input);
        if(feof(input)) {
            //printf("we got an EOF on first line of block\n"); //DEBUG
            exit(error(1,line,""));
        }
        if(!sscanf(buffer, "%s", command)) {
            exit(error(1,line,""));
        }
and then I fork, and run execlp in the child.

I know that to get a string with space delimited arguments I would simply read the string at buffer[(int)strlen(command)+1] (+1 for the space after the command and before the first argument), but how do I make it so that exec will dynamically pass through any number of arguments needed.

Is it easier to do this using execvp?

Also as a side note, I know the first argument has to be the program name. This is fine if command = tee (for example), because i could pass command as the first argument as well, but what if the command i'm running is "/some/file/path/program"? How can I pass "program" as the first parameter?

Thanks,
Luke