1.sizeof返回值是unsigned int类型,for(int i=3;i-sizeof(int)>=0;i--)
死循环。由于int 与unsigned int混合计算,返回值为unsigned int,恒大于等于0;死循环
知识点
2.管理系统
#include<stdlib.h>
#include<stdio.h>
#include<ctype.h>
#include<io.h>
#include<string.h>
#include<stdlib.h>
typedef struct p{
int id;//学号
char name[20];
char sex[5];
int math, english, C;
struct p* next;
}student;
typedef struct pff{
student* head;
student* tail;
int size;
}ppt;
void add(ppt* a) {
student *p=(student*)malloc(sizeof(student));
a->tail->next = p;
a->tail = p;
printf("输入id\n");
scanf_s("%d", p->id);
char c = getchar();
printf("输入姓名");
gets_s(p->name, 20);
printf("输入性别");
gets_s(p->sex, 5);
scanf_s("%d %d %d",& p->math,& p->english,& p->C);
}
void print(ppt*a){}
void exchange(ppt* a) {
print(a);
student* p = a->head;
int o;scanf_s("%d", &o);
if (a->size<o)printf("无信息");
for (int i = 0;i < o;i++)
p = p->next;
printf("更改学号1,名字2,性别3,高数成绩4,C语言成绩5,英语6");
int n,f;
scanf_s("%d", &n);
char j[100];
if (n == 3 || n == 2)gets_s(j, 100);
else if (n == 1)scanf_s("%d",& f);
else if (n > 3 && n < 7)scanf_s("%d", &f);
switch (n) {
case 2:strcpy_s(p->name,20, j);break;
case 3:strcpy_s(p->sex,5, j);break;
case 1:p->id = f;break;
case 4:p->math = f;break;
case 5:p->english = f;break;
case 6:p->C = f;
}
}
void delete(ppt*a){
};
void seek(ppt*a){
int n;
student* p = a->head;
char A[100];
int cc;
printf("依据学号查找1,姓名查找2");
scanf_s("%d", &n);
if (n != 1 && n != 2)printf("请规范操作");
else if (n == 1)scanf_s("%d", &cc);
else scanf_s("%s", A);
if (a->size == 0)printf("无此人");
else {
for (int i = 0;i < a->size;i++){
}
}
}
void save(ppt*a){
}
void choice(ppt*a) {
int n;
scanf_s("%d", &n);
switch(n){
case 1: add(a); break;
case 2: exchange(a); break;
case 3: delete(a); break;
case 4: seek(a); break;
case 5: save(a); break;
case 6:exit(1);break;
default : printf("error");
};
}
void menu() {
printf("*****学生管理系统*****\n");
printf("1.添加学生信息 2.更改学生信息\n");
printf("3.删除学生信息 4.查询学生\n");
printf("5.保存 6.退出\n");
}
int main() {
ppt a;
student *p=(student*)malloc(sizeof(student));
a.head = a.tai= p;
a.head->next =a->tail->next= NULL;
while (1) {
menu();
choice(&a);
}
return 0;
}