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 IS HEADER?

8 Answers   ProKarma, TCS,


#define MAX(x,y) (x) > (y) ? (x) : (y) main() { int i = 10, j = 5, k = 0; k = MAX(i++, ++j); printf("%d %d %d", i,j,k); } what will the values of i , j and k? }

14 Answers   CDAC, GATE, NDS, TCS,


where can function pointers be used?

2 Answers  


Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.

0 Answers  


Which are low level languages?

0 Answers  


Develop a flow chart and write a c program to find the roots of a quadratic equation ax2+bx+c=0 using switch and break statement.

1 Answers   TCS,


int zap(int n) { if(n<=1)then zap=1; else zap=zap(n-3)+zap(n-1); } then the call zap(6) gives the values of zap [a] 8 [b] 9 [c] 6 [d] 12 [e] 15

10 Answers   Wipro,


What are the types of pointers in c?

0 Answers  


#define min((a),(b)) ((a)<(b))?(a):(b) main() { int i=0,a[20],*ptr; ptr=a; while(min(ptr++,&a[9])<&a[8]) i=i+1; printf("i=%d\n",i);}

3 Answers  


When should volatile modifier be used?

0 Answers  


WAP &#8211; represent a char in binary format

4 Answers   Motorola, Wipro,


How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?

0 Answers  


Categories