Create an executable for a program in an interpreted language: Difference between revisions

Content added Content deleted
m (fixed some text)
(→‎{{header|AWK}}: Added sample input and output)
Line 314: Line 314:
using a suitable C compiler
using a suitable C compiler
</pre>
</pre>

Assuming hw.awk contains:
<lang awk>BEGIN \
{

printf( "Hello, World!\n" );

} # BEGIN</lang>

_hw_awk.c would contani:
<lang c>#include <stdio.h>
#include <errno.h>
static void w( char * line, FILE * tf )
{fputs( line, tf );
if( errno != 0 ){ perror( "temp" );exit( 2 ); }
}
int main( int argc, char ** argv )
{FILE * tf = fopen( "/tmp/t", "w" );
if( tf == NULL ){ perror( "temp" );exit( 1 ); }
w( "BEGIN \\\n", tf );
w( "{\n", tf );
w( " printf( \"Hello, World!\\n\" );\n", tf );
w( "} # BEGIN\n", tf );
fclose( tf );
system( "awk -f /tmp/t" );
remove( "/tmp/t" );
}</lang>