-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudentBase.c
72 lines (61 loc) · 1.47 KB
/
studentBase.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "mydecl.h"
#define N 5
typedef struct{
int year;
int month;
int day;
}Date;
typedef struct{
int id;
char name[20];
Date birth;
char major[20];
}Student;
//------------
void inputInfo(Student*);
void outputInfo(Student*);
void searchInfo(Student*,Date);
//-----------
int main(void){
Student students[N];
Date date;
inputInfo(students);
outputInfo(students);
printf("Enter a data<month,day>\n");
scanf("%d,%d",&date.month,&date.day);//fixed!learn!
searchInfo(students,date);
return 0;
}
void inputInfo(Student s[]){
int i;
printf("Enter %d student's Info(name,birhtday,major)\n",N);
for(i=1;i<=N;++i){
// printf("Enter %d student's Info(name,birhtday,major)\n",N);//learns
s[i].id=i;
scanf("%s",s[i].name);
scanf("%d%d%d",&s[i].birth.year,&s[i].birth.month,&s[i].birth.day);
scanf("%s",s[i].major);
}
}
void outputInfo(Student s[]){
int i;
printf(" Id Name \tBirthday\t Major\n");
for(i=1;i<=N;++i){
printf("%4d%14s %d/%d/%d %14s\n",
s[i].id,s[i].name,s[i].birth.year,s[i].birth.month,s[i].birth.day,s[i].major);
}
}
void searchInfo(Student s[],Date d){
int i;
for(i=1;i<=N;++i){
if(s[i].birth.month>d.month){
printf("%4d%14s %d/%d/%d %14s\n",
s[i].id,s[i].name,s[i].birth.year,s[i].birth.month,s[i].birth.day,s[i].major);
continue;
}
if(s[i].birth.month == d.month && s[i].birth.day > d.day){
printf("%4d%14s %d/%d/%d %14s\n",
s[i].id,s[i].name,s[i].birth.year,s[i].birth.month,s[i].birth.day,s[i].major);
}
}
}