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

what are bit fields in c?

0 Answers  


What is #line used for?

0 Answers  


Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?

0 Answers  


1 1 2 1 2 3 1 2 3 4 1 2 3 1 2 1 generate this output using for loop

2 Answers  


What is the use of extern in c?

0 Answers  






difference between semaphores and mutex?

1 Answers  


Explain what is wrong with this program statement? Void = 10;

0 Answers  


What are register variables in c?

0 Answers  


Define C in your own Language.

0 Answers   Motorola,


Why is c used in embedded systems?

0 Answers  


What does %d do in c?

0 Answers  


#include<stdio.h> void main() { char *str; long unsigned int add; str="Hello C"; add=&str[0]; printf("%c",add); } What is the output?

4 Answers   Infosys,


Categories