c pass variable as parameters to an exe

October 29, 2010 at 08:05:25
Specs: Windows XP, 4gb
Hi! How do you pass variables as parameters to an executable in c?

example: int x=123, y=321;
system("some_program.exe x y");

this code just passed x as in the letter x and not the 123.

I would like my c program to pass the value of the variable, and not the variable name.


See More: c pass variable as parameters to an exe

Report •


#1
October 29, 2010 at 08:38:03
For C? Build a string using vsprintf(), then pass that string to system().

How To Ask Questions The Smart Way


Report •

#2
October 30, 2010 at 08:18:10
Hi! Thanks but I already figured it out. :

#include<string.h>
#include<stdio.h>
main(){
char p1[100]="param1 ", p2[256]="param2", call_bat[256]="receive_two_parameters.bat ";

strcat(call_bat, p1);
strcat(call_bat, p2);

system(call_bat);
getch();
}


Report •
Related Solutions


Ask Question