GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  OOPS
Next Question 
 OOPS  |  Question 1 of 258    Print  
How do you write a program which produces its own source code as its output?

  
Total Answers and Comments: 10 Last Update: March 14, 2007   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by:
 

Hi,

  There are So many complex methods for that but i write the most effective and simple one  just write this ..

// program name avi.c

#include<stdlib.h>

void main()

{ //// write ur program logic here

getch();

system("type avi.c");

}

by the use of this system function from stdlib.h u can run any dos command from ur c program but please check the output for this only by running the exe of ur program ( in this case avi.exe)

Regards ,

Avinash Chaturvedi( Avi )



Above answer was rated as good by the following members:
gunturi.prabhakar, kavyacreamy, ravindra8055
June 27, 2005 05:02:37   #1  
abhijit        

RE: How do you write a program which produces its own source code as its output?
can i get the ans fr the question
Question : How do you write a program which produces its own source code as its output?

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 16, 2005 00:02:55   #2  
Anjaneyulu        

RE: How do you write a program which produces its own source code as its output?
/* Program to printf itself on console */
#include
int main(void)
{
FILE *in;
clrscr();
if ((in fopen( 8.c r )) NULL)
{
printf( Cannot open input file.n );
return 1;
}
while (!feof(in))
printf( c fgetc(in));
fclose(in);
getche();
return 0;
}

 
Is this answer useful? Yes | No
July 16, 2005 08:05:18   #3  
venu        

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

 
Is this answer useful? Yes | No
July 27, 2005 00:45:29   #4  
suhasini        

RE: How do you write a program which produces its own source code as its output?
Howdoes return1 and return 0 differ?
 
Is this answer useful? Yes | No
September 03, 2005 21:54:27   #5  
Santhanam        

RE: How do you write a program which produces its own source code as its output?
'return 0' indicates program is ended with no error and 'return 1' indicates program is ended with error.
 
Is this answer useful? Yes | No
September 12, 2005 09:03:06   #6  
Harish Kumar        

How to write a program who prints itself.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(int args char **argv)
{
char filename[20];
int i 0 k 0;
FILE *in;

while(argv[0][i] ! '\0')
if(argv[0][i++] '\\')
k i;
printf( d k);
for(i 0;argv[0][k] ! '.';i++ k++)
{
filename[i] argv[0][k];
}

filename[i] '\0';
strcat(filename .c );

if ((in fopen(filename r )) NULL)
{
printf( Cannot open input file.n );
return 1;
}
while (!feof(in))
printf( c fgetc(in));
fclose(in);
return 0;
}


 
Is this answer useful? Yes | No
October 10, 2005 08:40:04   #7  
Sudhakar        

RE: How do you write a program which produces its own ...
main() { char *a main() { char *a c s c; char b ' c'; printf(a b a b b); } ; char b ' '; printf(a b a b b); }
 
Is this answer useful? Yes | No
July 21, 2006 03:21:28   #8  
wasim        

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

#include<>

main()

{

FILE *p;

p fopen( filename r );

if(p null)exit(1);

while(!eof(p))

{

printf( c *p);

p++;

}

getche();

}


 
Is this answer useful? Yes | No
August 03, 2006 08:06:22   #9  
       

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

Hi

There are So many complex methods for that but i write the most effective and simple one just write this ..

// program name avi.c

#include<stdlib.h>

void main()

{ //// write ur program logic here

getch();

system( type avi.c );

}

by the use of this system function from stdlib.h u can run any dos command from ur c program but please check the output for this only by running the exe of ur program ( in this case avi.exe)

Regards

Avinash Chaturvedi( Avi )


 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
March 14, 2007 10:20:41   #10  
Manoj        

RE: How do you write a program which produces its own ...
All the solutions above are reading the source code with the files concepts.

find a solution where you do not have a source file to read the contents.

There is a macro or an attiribute which tells the compiler the name of the program function or the attribute. You can use that to get the source code. try out...!!!

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape