fwrite()

#include<stdio.h>
struct anik
{
    char nm[100];
    int id;
    char cn[100];
};
int main()
{
    FILE *anik;
    anik = fopen("ac.txt", "w");
    struct anik p;
    if(anik == NULL)
    {
        printf("File does not exist\n\n");
    }
    else
    {
        printf("File is open\n\n");
        printf("Enter Your Name : ");
        gets(p.nm);
        printf("Enter Your ID : ");
        scanf("%d", &p.id);
        printf("Enter Your Contact Number : ");
        scanf("%s", p.cn);

        fwrite(&p, sizeof(p), 1, anik);
        printf("\nFile is written successfully\n\n");
        fclose(anik);
    }
    return 0;
}

Comments