fprintf()

#include<stdio.h>
int main()
{
    FILE *anik;

    anik = fopen("bc.txt", "a");

    char ch[50];
    int age;

    if(anik == NULL)
    {
        printf("File Does Not Exist\n");
    }
    else
    {
        printf("File is Open\n");
        printf("Enter Your Name : ");
        gets(ch);
        printf("Enter Your Age : ");
        scanf("%d", &age);

        fprintf(anik,"Name = %s\nAge = %d\n", ch, age);

        printf("File is written successfully\n");
        fclose(anik);
    }

    return 0;
}

Comments