This program forks first, and then execlp starts, the calling program goes into two numbers, power and base.
int main(int argc, char *argv[]) { int pid = getpid(); printf("Calculator Process[%d]: started\n",pid); double base, power; sscanf(argv[1],"%d",&base); sscanf(argv[2],"%d",&power); double number = pow(base,power); printf("Calculator Process[%d]: %d ^^ %d == %d\n",pid,base,power,number); printf("Calculator Process[%d]: exiting\n",pid); return 1; }
Let's say I go to base 3, power 5. This is what I get:
base = 4263 - this also happens to be the PID.
power = -1
raised to power: 714477568
Calling line:
execlp("./calculator","./calculator",argv[1],argv[2],(char*)0);
When I print argvs, I get their value (like char *, but dumping fails).
Any ideas why I can't read the values ββcorrectly?
source share