| 
	
 | 
 Posted by Kimmo Laine on 01/25/07 07:54 
<balakrishnan.dinesh@gmail.com> wrote in message  
news:1169703809.714482.189280@m58g2000cwm.googlegroups.com... 
> hi frndz, 
>             I need to call a C program function from php code, Is that 
> possible, If it is ,then tell me how ? 
>           i.e,main() 
>               { 
>                    int callfunction(); 
>                    int i=2; 
>                    callfunction(i); 
>                } 
>                callfucntion(int i) 
>                { 
>                    if(i==1) 
>                    return 2; 
>                } 
> 
>             This is the C program which is in directory that have php 
> code too, So what i need is , From my php code ,i need to call the 
> callfunction() from that C program  . Is that possible. 
> or else anyother way to call c function from php code 
 
 
Not possible. You can't call a function inside another program written in  
totally different language in php. What you can do is you can write a  
program in c and call the program from command line with commandline  
arguments and echo the output. Then you can in php call the program and read  
the output using the built-in system functions like exec() or system() or  
whatever. 
 
Something like this: 
in php: 
echo system('myprogram 1'); 
 
myprogram.c: 
// Apolgize my horrible C, it's been a million(?) years since i wrote C 
main(argc, argv){ 
    int i; 
    i = atoi(argv[1]); 
    j = callfunction(i); 
    printf('%d', j); 
} 
 
This is just a very raw example, but you'll get the basic idea, right? 
 
--  
"Ohjelmoija  on  organismi  joka  muuttaa  kofeiinia  koodiksi" - lpk 
http://outolempi.net/ahdistus/ - Satunnaisesti pδivittyvδ nettisarjis 
spam@outolempi.net | rot13(xvzzb@bhgbyrzcv.arg)
 
  
Navigation:
[Reply to this message] 
 |