Re: How to call another separate program and passing some variables in C?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



johnny_xing wrote:
Hi,

I tried as what Hlalesh said and it doesn’t work.

Here is what I have:

In program 1:

system(“/usr/local/src/program2 1”);

In program 2:
int main(int argc, char *argv[])
{
int input1;
char buffer[10];
sprintf(buffer, argv[0]);

printf("buffer is %s\n", buffer);
input1 =atoi(buffer);
printf("input1 value is %d\n",input1);
}

The output is:

buffer is /usr/local/src/parallel/asterisk
input1 value is 0


argv[0] is always the name of the called binary. To get the arguments, you need to start with argv[1].

Surely you can see that atoi("/usr/local/src/parallel/asterisk") is 0 as there is no way to convert "/usr/local/src/parallel/asterisk" to an integer.


/Per Jessen, Zurich
	

--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux