Re: PHP and C

From: Date: Sun, 19 Jul 2015 12:20:56 +0000
Subject: Re: PHP and C
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-325004@lists.php.net to get a copy of this message
Why do you need to use stdin then? Couldn't you call the C program like this: <?php $someNumber = 1234; /path/to/cprogram $someNumber ?> and in your C program #include <stdio.h> int main(char **args, int argc) { int num = atoi(args[1]); // some processing printf("%d", numDerived); } On Sun, 19 Jul 2015 at 15:31 Ethan Rosenberg < erosenberg@hygeiabiomedical.com> wrote: > On 07/18/2015 05:40 AM, German Geek wrote: > > What do you actually want to achieve? > > > > On Sat, 18 Jul 2015 at 21:39 German Geek <geek.de@gmail.com> wrote: > > > >> Of course you need to give the variable $someNumber a value. > >> > >> On Sat, 18 Jul 2015 at 03:45 Ethan Rosenberg < > >> erosenberg@hygeiabiomedical.com> wrote: > >> > >>> Thanks - > >>> > >>> On 07/17/2015 12:34 AM, German Geek wrote: > >>>> You cannot run a C program and grab input from PHP interactively! You > >>> would have to pipe the input > >>>> in as so: > >>>> > >>>> // untested! > >>>> $number = echo $someNumber | > >>>> /var/www/TestScanf; > >>>> echo 'number in php<br />'; > >>>> > >>>> Also, returning the number num in C's main function is wrong. You > >>> should return 0 if successful and > >>>> another int if the program has an error. > >>>> > >>>> > >>>> > >>> <snip> > >>> > >>> You cannot run a C program and grab input from PHP interactively! > You > >>> would have to pipe the input > >>> in as so: > >>> > >>> // untested! > >>> $number = echo $someNumber | /var/www/TestScanf; > >>> echo 'number in php<br />'; > >>> > >>> Also, returning the number num in C's main function is wrong. You > should > >>> return 0 if successful and > >>> another int if the program has an error. > >>> > >>> > >>> CODE > >>> > >>> > >>> $number = echo $someNumber | /var/www/TestScanf; > >>> //$number = /var/www/TestScanf; > >>> echo 'number in php<br />'; > >>> > >>> echo $number; > >>> > >>> OUTPUT > >>> > >>> > >>> Notice: Undefined variable: someNumber in /var/www/Scanf.php on line 36 > >>> number in php > >>> Enter your Number 0 > >>> > >>> TIA > >>> > >>> Ethan > >> > --------- > > Thanks - > > > What do you actually want to achieve? > > To input an integer into a PHP script, with the number being generated by > an external C program. > > TIA > > Ethan > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#325004) next »