Page 1 of 1

getting a C file & compile it!

Posted: Sun Dec 14, 2003 11:49 am
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 :(

Posted: Sun Dec 14, 2003 11:52 am
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.

Posted: Sun Dec 14, 2003 1:10 pm
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!!

Posted: Sun Dec 14, 2003 4:44 pm
by Miss.Apache
i tried another version for compiler & i found the tmp.c
but the message still appears!!