Program
#include<stdio.h>
int main(){
FILE *fp;
char c;
fp = fopen(__FILE__,"r");
do{
c= getc(fp);
putchar(c);
}
while(c!=EOF);
fclose(fp);
return 0;
}
Result
#include<stdio.h>
int main(){
FILE *fp;
char c;
fp = fopen(__FILE__,"r");
do{
c= getc(fp);
putchar(c);
}
while(c!=EOF);
fclose(fp);
return 0;
}
Explanation :
fp = fopen(__FILE__,"r");
Suppose we have saved this source code at path –
c://tc/bin/file1.c
then
fp = fopen(__FILE__,"r");
will be expanded as –
fp = fopen("c://tc/bin/file1.c","r");