as

Thursday, 13 November 2014

Appending Files in C


To append contents to the file, you will have to open the file in append mode.

#include <stdio.h>                  
#include <string.h>
main( )
{
    FILE *f;
    char s1[25];
    int i;
    f = fopen("abc.txt","a");
    /* open for writing */
    strcpy(s1,"This is an example line.");

    for (i = 11; i <= 20; i++)
      fprintf(f,"%s Line number %d\n", s1, i);
    fclose(f); /* close the file before ending program */
}






No comments:

Post a Comment

Leave your valuable feedback. Your thoughts do matter to us.

Sponsored Links

Popular Posts

Comments

ShareThis