By trade I'm a PHP programmer and wanted to test writing a C program, sending it arguments and using it's output in PHP using shell_exec()
.
Anyway, I wrote this code simply to add two numbers together:
#include <stdio.h>
int leftop, rightop, result;
int main(int argc, char *argv[])
{
leftop = (int) argv[1];
rightop = (int) argv[2];
result = leftop + rightop;
printf("The result of %i add %i = %i\n", leftop, rightop, result);
getchar();
return 0;
}
i compile it with MinGW
using gcc -o main.c mycprogram.exe
.
When I run the program (either using shell_exec()
(php) or from command line) I get the following results.
./mycprogram.exe 25 25
The result of 7150824 add 7149184 = 14300008
then i run it again and get:
The result of 6692040 add 6692072 = 13384112
obviously I expect the result to be 50
.
How come I'm not getting the correct results?