Solved programming problem

How to Use append mode a using file in C.

Source code

#include <stdio.h>

int main()

{

     char n[100];

    FILE *ptr; ///FILE type pointer

    printf("Please Enter Massage: ");

    gets(n);

    ptr=fopen("output.txt","a"); ///read the text file and add new string at the end

    fprintf(ptr,"%s",n);

    fclose(ptr);

    return 0;

}

Output

1st Step:

Create a text file and save some value or massage there.

2nd Step:

Run The program and enter any massage.

Please Enter Massage: code to haven

Join the discussion

Add your comment