getting a C file & compile it!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Miss.Apache
Forum Newbie
Posts: 10
Joined: Sun Dec 14, 2003 11:49 am

getting a C file & compile it!

Post by Miss.Apache »

hello,

this code will be an action when a student click a submit button in "html page"

i have aproblem with it.. :(
always i recieved this messege:

Compiled failed!
The output from compiler is:

////////////////////////////////////////////////////////////////////////////////////////////////////////
Turbo C++ Version 3.00 Copyright (c) 1992 Borland International
Error: Unable to open 'tmp.c'
//////////////////////////////////////////////////////////////////////////////////////////////////////


<?
$fp = fopen('C:\TC\tmp.c', "w+"); //Create a temporary file to compile

if( !fwrite( $fp, stripslashes($_POST['src']))) //because php will add ''' before '"'
//in the string, so we should delete ''', funtion stripslashes
//does this, and $_POST is a default variable by system to get
//form from user.
{
echo "Faild creating temporary file for compiler";
exit;
}
fclose($fp);

$command="TC\\tcc tmp.c";
$command='tcc tmp.c';

unset($result); //$result is an array to get return string from function exec. we should initialized it.

exec('c:\TC\tcc.exe tmp.c', $result, $var);
// Execute the command.



if($var==0)
echo "Your program compiled successfully. <br>";
else
echo "Compiled failed! <br>";

echo "The output from compiler is:<br>";
echo "<br>////////////////////////////////////////////////////////////////////////////////////////////////////////<br>";

for($i=0;$result[$i];$i++) //print the return string in $result.
{
echo $result[$i]."<br>";
}
echo "//////////////////////////////////////////////////////////////////////////////////////////////////////<br>";
?>

any one knows the problem?
help please :(
User avatar
MrNonchalant
Forum Commoner
Posts: 29
Joined: Wed Jul 17, 2002 2:15 am

Post by MrNonchalant »

Try putting a temp.c file there yourself and running the compiler manually. Also try making the path to temp.c in the parameters a full path instead of a relative path.
Miss.Apache
Forum Newbie
Posts: 10
Joined: Sun Dec 14, 2003 11:49 am

Post by Miss.Apache »

i put it manually but nothing change!

what do you mean by:try making the path to temp.c in the parameters a full path instead of a relative path.?

where?

i make it in the fopen?

-----

i tried another version for compiler & i found the tmp.c
but the message still appear!!
Last edited by Miss.Apache on Sun Dec 14, 2003 4:48 pm, edited 1 time in total.
Miss.Apache
Forum Newbie
Posts: 10
Joined: Sun Dec 14, 2003 11:49 am

Post by Miss.Apache »

i tried another version for compiler & i found the tmp.c
but the message still appears!!
Post Reply