C programming: C program for appending a line to a text file.

#include<stdio.h>
#include<conio.h>

//NOTE:if using TurboC append.txt should be stored in C:\TC\BIN
void main()
{
FILE *fp;
char c;
clrscr();

fp=fopen("append.txt","a"); //opens append.txt in append mode

printf("Enter a string ending with character $\n");
while((c=getchar())!='$')
  putc(c,fp);  //append in the file append.txt

fclose(fp); //close the file pointed by fp
getch();
}

 

Please follow and like us:

Leave a Comment