system
, unlike printf
does not accept multiple parameters, it only accepts one parameter, a const char *command
. So you need to build your complete command string first in memory and then pass it to system.
An example would be:
char buf[32];
sprintf(buf, "echo %d", a);
system(buf);
You need to take care not to write more chars into buf than buf has space for. You might want to read the man page for snprintf
to rewrite the code in a safer way.
Also: if your code really compiled, then please compile with a higher warning level. At least that would have given you warnings that you are calling system with more parameters than you should.