C Program To Append Contents Into A File


#include< conio.h >
#include< stdio.h >
#include< process.h >
void main()
{
FILE *fp;
char c;
clrscr();
printf("Contents of the file =>\n");
fp=fopen("demo.txt","r");
while(!feof(fp))
{
c=fgetc(fp);
printf("%c",c);

 }
fp=fopen("demo.txt","a");
if(fp==NULL)
{
printf("file can't append\n");
exit(1);
}
printf("\nEnter the string to append\n");
while(c!='.')
{
c=getche();
fputc(c,fp);
}
fclose(fp);
printf("file contents after appending\n");
fp=fopen("demo.txt","r");
while(!feof(fp))
{
c=fgetc(fp);
printf("%c",c);
}
}

----------------------------------------------------------
OUT PUT:
----------------------------------------------------------
Contents of the file =>
This is c prorgam.

Enter the string to append
I upload C++ prorams soon.

File contents after appending
This is c prorgam.I upload C++ prorams soon.

0 comments :