getting a C file & compile it!
Posted: Sun Dec 14, 2003 11:49 am
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
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