You are here: Re: how to call C program function from PHP « PHP Programming Language « IT news, forums, messages
Re: how to call C program function from PHP

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]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация