From: Per Jessen <per@computer.org>
To: C programming list <linux-c-programming@vger.kernel.org>
Subject: Re: How to call another separate program and passing some variables in C?
Date: Wed, 15 Oct 2008 11:05:23 +0200 [thread overview]
Message-ID: <48F5B253.4010200@computer.org> (raw)
In-Reply-To: <528704E66F154167B2EA3F70DDCFFF94@johnny>
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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2008-10-15 9:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-14 10:48 How to call another separate program and passing some variables in C? johnny_xing
2008-10-14 11:12 ` Re : " korfuri
2008-10-15 6:27 ` johnny_xing
[not found] ` <4f5c2ba10810142334o6dbca046r52eb267c8da28aa9@mail.gmail.com>
2008-10-15 8:31 ` johnny_xing
2008-10-15 9:05 ` Per Jessen [this message]
[not found] ` <5F844C5CE0B949348F25CDBF9B3FA11D@johnny>
[not found] ` <4f5c2ba10810150150k153b051fod1440a14037cd16c@mail.gmail.com>
[not found] ` <4f5c2ba10810150152s6c6307fi1fde09505b31a8bc@mail.gmail.com>
2008-10-15 9:10 ` johnny_xing
[not found] ` <4f5c2ba10810150227k44321974n4fe51ff28e470e2c@mail.gmail.com>
2008-10-15 9:35 ` johnny_xing
2008-10-16 0:41 ` Jianjun Kong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48F5B253.4010200@computer.org \
--to=per@computer.org \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.