From: korfuri@gmail.com
To: johnny_xing <johnny_xing@banshing.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re : How to call another separate program and passing some variables in C?
Date: Tue, 14 Oct 2008 13:12:29 +0200 [thread overview]
Message-ID: <c15440c50810140412r7df6c411xdf24dd6a16590132@mail.gmail.com> (raw)
In-Reply-To: <DF93814AEDB44B7484B8BF8F416AA50D@johnny>
2008/10/14, johnny_xing <johnny_xing@banshing.com>:
> Hi,
>
> Forgive me if my question is so simple as I am a newbie to programming..
>
> I have two C programming and I want to call second C file within my first C
> program, upon calling, I need to pass some variables (like 1 or 0) to the
> second program.
>
> Can anyone tell me how to do? I searched system() but it seems not be able
> to do this.
>
> Thanks & Best Regards,
>
> Johnny
>
>
> --
> 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
>
Hi,
You can use system() if you build the command-line (e.g. with
sprintf()) to pass the arguments you want. Then you can access it in
your 2nd program with argc/argv.
An alternative is to use fork() and execve(). Please note that you
have to convert each argument to a string so execve() can use it. Here
again you can use sprintf() for this purpose.
But are you sure you need two separate programs ? You can build 2 C
files together into one binary. That makes passing variables much
easier as it results to a normal function call.
Hope this will help
Regards,
Uriel
--
Uriel "Korfuri" Corfa
Epitech student
next prev parent reply other threads:[~2008-10-14 11:12 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 ` korfuri [this message]
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
[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=c15440c50810140412r7df6c411xdf24dd6a16590132@mail.gmail.com \
--to=korfuri@gmail.com \
--cc=johnny_xing@banshing.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).