system()
only takes one argument - a const char*
. In fact,
system( "rar e -p%s wingen.rar", pword );
won't compile - the compiler will complain that you've passed too many arguments to system()
. The reason that:
system( "rar e -p%s wingen.rar", pword );
compiles is that you have wrapped your two strings in parenthesis. This has the effect of evaluating the expression inside, which consists of the comma operator operating on two strings. The comma operator has the effect of returning the value of the second argument, so you end up calling:
system( pword );
Which in your example is equivalent to:
system( "pwd" );
And pwd
isn't a command on your system (although on POSIX systems it is... but I digress). What you want to do has been explained in the other answers but for completeness I'll mention it too - you need to format your string using sprintf
:
char buff[256];
sprintf( buff, "rar e -p%s wingen.rar", pword );
or you can concatenate strings, which might be a little bit faster (although for such a short string, it probably won't make a difference):
char buff[256] = "rar e -p";
strcat( buff, pword );
strcat( buff, " wingen.rar" );
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…