Saturday, October 19, 2013

Program to print it's Own Source code

Program:
#include<stdio.h>    
#include<conio.h>    
int main()
{
clrscr();
FILE *fp;
char c;
fp = fopen(__FILE__,"r");
do
{
c= getc(fp);
putchar(c);
}
while(c!=EOF);
fclose(fp);
getch();
return 0;
}

Output:

#include<stdio.h>  
#include<conio.h>    
int main()
{
clrscr();
FILE *fp;
char c;
fp = fopen(__FILE__,"r");
do
{
c= getc(fp);
putchar(c);
}
while(c!=EOF);
fclose(fp);
getch();
return 0;
}

No comments: