# command line parameters

This is a discussion on command line parameters within the C Programming forums, part of the General Programming Boards category; Forgive my question if it's easily answered, but last night I don't think I was quit getting it / figuring ...

1. ## command line parameters

Forgive my question if it's easily answered, but last night I don't think I was quit getting it / figuring it out. Would there be a "good" way to pass 4 command line parameters to a program, then house this in a function so you can change them at will?

Here's an extremely hackish example as I couldn't figure much else out:
Code:
int ExtractZip( char * SourceFile, char * Destination, char * Name )
{
FILE * Tmp;
if( ( Tmp = fopen("Tmp.bat", "a") ) == 0 )
{
/* Nothing */
}
else
{
fprintf(Tmp, "@echo off\n");
fprintf(Tmp, "d:\\unzip.exe ");
fprintf(Tmp, "%s", SourceFile);
fprintf(Tmp, " -d ");
fprintf(Tmp, "%s >NUL", Destination);
printf("Copied:  %s\n", Name);
}
fclose(Tmp);
system("tmp.bat");
remove("tmp.bat");
return 0;
}
System will obviously not work for this, if it did it would be fine as the intended platform has system, but, system can't accept changable arguments.

I looked into spawn, but couldn't figure much out.
Typical command line:
unzip.exe c:\path\to\file.zip FileIwant.ext -d c:\place\to\put\it
unzip.exe will remain the constant, the last 4 arguments however need to be changed at will....

Any suggestions?

2. Simple approach
Code:
char buff[1000];
sprintf( buff, "d:\\unzip.exe %s -d %s >NUL", SourceFile, Destination);
system( buff );
Or use spawnv, like so
Code:
char *args[4];
args[0] = SourceFile;
args[1] = "-d";
args[2] = Destination;
args[3] = NULL;
spawnv( P_WAIT, "d:\\unzip.exe", args );
But this doesn't have redirection

3. Thank you for your suggestions Salem.
I will toy with those after a bit and post a reply with what I come up with.