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

main() { char *p; p="Hello"; printf("%c\n",*&*p); }

2 Answers   ME,


Not all reserved words are written in lowercase. TRUE or FALSE?

0 Answers  


What is the use of in c?

0 Answers  


how we do lcm of two no using c simple if while or for statement

1 Answers  


If i have an array 0 to 99 i.e,(Size 100) I place the values 1 to 100 randomly like a[0]=29,a[1]=56 upto array[99].. the values are only between 1 to 100. getting the array values by using scanf.. If i entered one wrong element value line a[56]=108. how can i find it.. and also how to find the missing value in 1 to 100.. and i want to replace the missing values.. any one of them know please post your answer..

0 Answers   IBM, Wipro,






Does c have function or method?

0 Answers  


What is ambagious result in C? explain with an example.

0 Answers   Infosys,


What are linker error?

0 Answers  


Why n++ execute faster than n+1 ?

2 Answers  


what is difference between userlevel threads and kernel level threads ?what are the trades offs between these two approaches ? what approach is most frequently used and why ?

1 Answers  


What is array within structure?

0 Answers  


how to go with this?

1 Answers   Wipro,


Categories