GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Programming  >  C++

 Print  |  
Question:  How do you write a program which produces its own source code as its output?



June 06, 2006 06:41:06 #1
 bappa   Member Since: Visitor    Total Comments: N/A 

RE: How do you write a program which produces its own ...
 

write this program and save it as pro.c....run....it will show the program to the consol and write the source code into data.txt file...................

#include<stdio.h>
void main()
{
 FILE *fp,*ft;
 char buff[100];
 fp=fopen("pro.c","r");
 if(fp==NULL)
 {
  printf("ERROR");
 }
 ft=fopen("data.txt","w+");
 if(ft==NULL)
 {
  printf("ERROR");
 }
 while(getc(fp)!=EOF)
 {
  
  fscanf(fp,"%s",buff);
  printf("%s\n",buff);
  fprintf(ft,"%s\n",buff);
 }
}

     

 

Back To Question