-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgrade.c
39 lines (37 loc) · 847 Bytes
/
grade.c
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
36
37
38
39
//program to print grade from a file
//grade A if marks>=80
// B if marks>=60 and <80
// C if marks<60
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
struct record
{
char name[20];
int roll;
int marks;
} student;
FILE *fp;
int choice = 1;
fp = fopen("stu", "rb");
if (fp == NULL)
{
printf("Error in openning file\n");
exit(1);
}
printf("\nName\t\tMarks\t\tGrade\n\n");
while (fread(&student, sizeof(student), 1, fp) == 1)
{
printf("%s\t\t", student.name);
printf("%4d\t\t", student.marks);
if (student.marks >= 80)
printf("A\n");
else if (student.marks >= 60)
printf("B\n");
else
printf("C\n");
}
fclose(fp);
return 0;
}