Sunday, 15 December 2013

C Program to Display its own Source Code as its Output

#include < stdio.h>

int main()
{
FILE *fp;
char ch;

fp = fopen(__FILE__,"r");
do
{
ch = getc(fp);
putchar(ch);
}
while (ch != EOF);
fclose(fp);
return 0;
}

Output

  
/*
* display its own source code as its output
*/
#include

int main ( )
{
FILE * fp;
char ch;

fp = fopen ( __FILE__,"r" ) ;
do
{
ch = getc ( fp ) ;
putchar ( ch ) ;
}
while ( ch ! = EOF ) ;
fclose ( fp ) ;
return 0 ;
}

For More Details Please Visit Ictjobs.info

No comments: