HOME

Tuesday, April 14, 2015

C PROGRAM FOR FILE HANDLING TO WRITE DATA IN FILE

#include<stdio.h>
#include<conio.h>
struct student
{
    char name[20];
    int age;
    int mark;
};
void main()
{
    FILE *fp;
    int i,n;
    char name[20];
    fp=fopen("file.txt","w");
    printf("how many data you want to store\n");
    scanf("%d",&n);
    struct student s[20];
    for(i=0;i<n;i++)
    {
    printf("name%d=\t",i+1);
    scanf("%s",s[i].name);
    fprintf(fp,"%s\t",s[i].name);
    printf("age%d=\t",i+1);
    scanf("%d",&s[i].age);
    fprintf(fp,"%d\t",s[i].age);
    printf("mark%d=",i+1);
    scanf("%d",&s[i].mark);
    fprintf(fp,"%d\n",s[i].mark);
    }
    fclose(fp);
}

No comments:

Post a Comment