Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / satish

using FILE concept we can achieve this

main()
{
FILE *fp;
FILE *fp1;
char ch;
int c=0;
clrscr();
fp=fopen("c:\cc.txt","r");
fp1=fopen("abc.txt","w");
if(fp==NULL)
{
printf("\n source file opening error");
//exit(1);
}
else if(fp1==NULL)
{
printf("\n target file opening error");
//exit(1);
}
while(!feof(fp))
{
ch=fgetc(fp);
fputc(ch,fp1);
c++;
}
fclose(fp1);
fclose(fp);
fp1=fopen("abc.txt","r");
while(!feof(fp1))
{
ch=fgetc(fp1);
//fprintf(fp1,"%c",ch);

printf("%c",ch);
}
fclose(fp1);
printf("\n %d bytes copied",c);
c=fcloseall();
printf("\n%d files closed",c);
getch();
}

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to Throw some light on the splay trees?

1048


What is sizeof array in c?

1022


The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?

1255


How to delete a node from linked list w/o using collectons?

2767


What is pass by reference in c?

1170


Difference between malloc() and calloc() function?

1186


What are enums in c?

1181


What is maximum size of array in c?

1025


any restrictions have on the number of 'return' statements that may be present in a function. a) no restriction b) only 2 return statements c) only 1 return statements d) none of the above

1127


How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?

1014


What is the purpose of macro in C language?

1101


Can 'this' pointer by used in the constructor?

1080


How can I avoid the abort, retry, fail messages?

1121


Which built-in library function can be used to match a patter from the string?

1288


WRITE A PROGRAM TO MERGE TWO SORTED ARRAY USING MERGE SORT TECHNIQUE..

2024