Web lists-archives.com

Re: [PHP] PHP and C




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.


On Fri, 17 Jul 2015 at 16:21 Ethan Rosenberg <
erosenberg@xxxxxxxxxxxxxxxxxxxx> wrote:

> Dear list -
>
> PHP script calls a C program --
>
>
>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <html>
>      <head>
>          <!--  Scanf.php  -->
>          <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
>          <style>
>              body{
>                  background-color: #89caeb;
>                  width:100%;
>                  height:100%;
>                  position: relative;
>                     font-family: "Helvetica", "Arial" , "Liberation Sans",
> "Free sans", sans-serif;
>                  overflow-y: scroll;
>               }
>              .wgh{
>                  font-size: 14pt;
>                  align: center;
>                  font-weight: bold;
>              }
>
>          </style>
>      </head>
>          <body>
>
>
> <?php
>
> /*
>   * To change this license header, choose License Headers in Project
> Properties.
>   * To change this template file, choose Tools | Templates
>   * and open the template in the editor.
>   */
> error_reporting(E_ALL | E_NOTICE);
> ini_set('display_errors','1');
>
>
> $number = `/var/www/TestScanf`;
> echo 'number in php<br />';
>
> echo  $number;
>
> ?>
>          </body>
> </html>
>
>
> //TestScanf.c //works perfectly as a stand alone
> #include <stdio.h>
>
> int main(void)
> {
>      int num;
>
>      printf("Enter your Number  ");
>      scanf("%d", &num);
>
>      printf("%d\n", num);
>      return (num);
>
> }
>
> Output -
>
> number in php
> Enter your Number 0
>
> TIA
>
> Ethan
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>