-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.cpp
More file actions
46 lines (44 loc) · 1.4 KB
/
add.cpp
File metadata and controls
46 lines (44 loc) · 1.4 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>
#include "student.h"
extern NodeType *head;
void Add(){
StType st;
while(1){
system("cls");
printf("\n\n\n******************** 输 入 信 息 ********************\n");
printf("\n请输入学生住宿信息\n\n");
printf("学号:");
scanf("%s",st.sno);
printf("姓名:");
scanf("%s",st.name);
printf("楼号:");
scanf("%d",&st.building);
printf("房间号:");
scanf("%d",&st.room);
printf("班级名:");
scanf("%s",st.className);
NodeType *s,*r;
r = head;
while(r->next != NULL && strcmp(r->next->data.sno,st.sno)){
r = r->next;
}
if(r->next != NULL && strcmp(r->next->data.sno,st.sno) == 0){ //存在重学号的记录,则提示相应信息
printf("\t>>学号重复\n");
}else{
s = (NodeType *)malloc(sizeof(NodeType));//新建一个学生节点
s->data = st;
s->next = r->next;
r->next = s;
printf("新增的信息为:\n");
printf("Record: 学号 姓名 楼号 房间号 班级名\n");
printf("%18s%9s%6d%10d%13s\n",s->data.sno,s->data.name,s->data.building,s->data.room,s->data.className);
}
printf("是否继续追加(y/n)?");
if(tolower(getch()) == 'n')
break;
}
}