Opens existing file and adds a line to the end - C File

C examples for File:File Operation

Description

Opens existing file and adds a line to the end

Demo Code

#include <stdio.h>
#include <stdlib.h>

FILE * fptr;/*w  w  w .j  ava 2 s .  com*/

int main()
{
    fptr = fopen("C:\\test\\BookInfo.txt","a");
    if (fptr == 0)
    {
        printf("Error opening the file! Sorry!\n");
        exit (1);
    }
    fprintf(fptr, "\nthis is a test!\n");

    fclose(fptr);
    return(0);
}

Related Tutorials