Say i have an exe, lets say sum.exe. Now say the code for sum.exe is
void main ()
{
int a,b;
scanf (\"%d%d\", &a, &b);
printf (\"%d\", a+b);
}
>
The easiest way I know for doing this is by using the popen()
function. It works in Windows and UNIX. On the other way, popen()
only allows unidirectional communication.
For example, to pass information to sum.exe
(although you won't be able to read back the result), you can do this:
#include
#include
int main()
{
FILE *f;
f = popen ("sum.exe", "w");
if (!f)
{
perror ("popen");
exit(1);
}
printf ("Sending 3 and 4 to sum.exe...\n");
fprintf (f, "%d\n%d\n", 3, 4);
pclose (f);
return 0;
}