Hi all,
While googling for some c puzzles/questions i found one good question.
Que: Write a small C program, which while compiling takes another
program from input terminal, and on running gives the result for the
second program. (NOTE: The key is, think UNIX).
Suppose, the program is 1.c
Then, while compiling
$ gcc -o 1 1.c
int main()
{
printf("Hello World\n");
}
^D
$ ./1
Hello World
$
What i have done is
[EMAIL PROTECTED] ~]$gcc -o test -x c -
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
[EMAIL PROTECTED] ~]$./test
Hello World
[EMAIL PROTECTED] ~]$
It worked, but the question is "Write a small C program,...."
So, I am not sure if this is the solution for above question.
Am I doing the write thing?
Is there any other way to do this?
thanks,
Dipak