-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfile_record.c
More file actions
32 lines (32 loc) · 786 Bytes
/
file_record.c
File metadata and controls
32 lines (32 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
int main()
{
FILE *f;
int n,rno,tmarks;
char fname[30],name[30];
printf("Enter file name:");
gets(fname);
f = fopen(fname,"w");
if(f==NULL)
{
printf("File could not be opened!");
return -1;
}
printf("Enter no:of records:");
scanf("%d",&n);
printf("Enter student details:\n");
fflush(stdin);
fprintf(f,"%s","Student details\n");
for(int i=0;i<n;++i)
{
printf("\nRoll No:");
scanf("%d",&rno);
printf("Student name:");
scanf("%s",name);
printf("Total marks:");
scanf("%d",&tmarks);
fprintf(f,"\nRoll No: %d \nStudent name: %s \nTotal marks: %d \n",rno,name,tmarks);
}
fclose(f);
return 0;
}