-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path1_write_read_student_details.c
More file actions
35 lines (32 loc) · 967 Bytes
/
1_write_read_student_details.c
File metadata and controls
35 lines (32 loc) · 967 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
33
34
35
//WAP to input name, roll no, marks of n students and store them in file/ read from file also.
#include <stdio.h>
struct studentDetails{
char name[50];
int roll;
int marks;
}data[10];
int main(){
printf("Enter the name, roll no and marks of 10 students:\n");
for(int i=0; i<10; i++){
printf("Name: ");
scanf("%s",data[i].name);
printf("Roll: ");
scanf("%d",&data[i].roll);
printf("Marks: ");
scanf("%d",&data[i].marks);
}
FILE *fp = fopen("student_details.txt", "a");
for(int i=0; i<10; i++){
fprintf(fp, "%s\t%d\t%d\t\n", data[i].name, data[i].roll, data[i].marks);
}
printf("Entered Data: \nName\tRoll\tMarks\n");
fclose(fp);
fp = fopen("student_details.txt", "r");
char name[50];
int roll, marks;
while( fscanf(fp, "%s%d%d", name, &roll, &marks) != EOF ){
printf("%s\t%d\t%d\n", name, roll, marks);
}
fclose(fp);
return 0;
}