-
Notifications
You must be signed in to change notification settings - Fork 1
/
student.c
49 lines (41 loc) · 1019 Bytes
/
student.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
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
struct student
{
char name[40];
int id;
float grade;
}
struct Student s[10];
// setting up rules for comparison
// to sort the students based on names
int comparator(const void* p, const void* q)
{
return strcmp(((struct Student*)p)->name,
((struct Student*)q)->name);
}
int main()
{
int N, *i = 0;
/* get data */
printf("Enter data....");
for(i = 0; i < N; i++)
{
s[i].roll = i + 1;
printf("Student number: %d", i);
printf("Enter name: ");
scanf("\n%s", &s[i].name);
printf("Enter id: ");
scanf("\n%d", &s[i].id);
printf("Enter grade: ");
scanf("\n%lf", &s[i].grade);
}
/* Display data */
for(i = 0; i < N; i++)
{
printf("Student number: %d", i + 1);
printf("Name: ");
puts(s[i].name);
printf("\nID: %d", s[i].id);
printf("\nGrade: %lf", s[i].grade);
}
}