How do you write a program which produces its own source
code as its output?

Answers were Sorted based on User's Feedback



How do you write a program which produces its own source code as its output?..

Answer / vivek

printitself.c

#include <stdio.h>

int main()
{

char ch;
FILE *file;

file=fopen("printitself.c","r");

while((ch=fgetc(file))!=EOF)
printf("%c",ch);

return 0;
}

Is This Answer Correct ?    19 Yes 2 No

How do you write a program which produces its own source code as its output?..

Answer / abhinav gupta

Try to google....quine Problem...

one solution is

main(){char *c="main(){char
*c=%c%s%c;printf(c,34,c,34);}";printf(c,34,c,34);}

Is This Answer Correct ?    3 Yes 0 No

How do you write a program which produces its own source code as its output?..

Answer / sharath

can we use system() to print source code of a file??

if yes please with an example.
also explain how to execute please please
i am in an urgent need.
please

Is This Answer Correct ?    0 Yes 0 No

How do you write a program which produces its own source code as its output?..

Answer / abhishek

#include <stdio.h>

static char prog[] = "#include <stdio.h>%c%cstatic char prog[] = %c%s%c;%c%cint main(void)%c{%c printf(prog, 10, 10, 34, prog, 34, 10, 10, 10, 10, 10, 10, 10);%c return 0;%c}%c";

int main(void)
{
printf(prog, 10, 10, 34, prog, 34, 10, 10, 10, 10, 10, 10, 10);
return 0;
}

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More C Interview Questions

why effort estimation is important?

1 Answers  


Where is volatile variable stored?

0 Answers  


write the function int countchtr(char string[],int ch);which returns the number of timesthe character ch appears in the string. for example the call countchtr("she lives in Newyork",'e') would return 3.

6 Answers  


Difference between MAC vs. IP Addressing

0 Answers  


What are types of structure?

0 Answers  






how write a addtion of two single dimensional array using of pointer in c language?

3 Answers   DRDO,


Define C in your own Language.

0 Answers   Motorola,


who is the editor of 'pokemon'?

1 Answers  


What is wrong in this statement?

0 Answers  


what will be the output of the following program, justify? #define TEST int TEST getdata() { static i; i+=10; return i; } main() { int k; k = getdata(); }

3 Answers  


What is the use of ?

0 Answers  


there is two conditions , 1. while using for loop for printing 1 to 50 no's simulteneous 2. while using printf functios for printing 1 to 50 no's simulteneous with or without using variables who will take more time for compiling and execution? explain in details with reason?

1 Answers  


Categories