该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
错误18error C2040: “FineStu”:“Student *(int)”与“int ()”的间接寻址级别不同e:\vs\study\study\study.c1441Study
#include
#include
#include
#include
typedef struct StudentManage{ //学生信息结构体
int id;
char name[21];
char sex[3];
short age;
struct StudentManage* next;
}Student;
static Student* G_Head = NULL; //链表头
static Student* G_Current = NULL; //记录当前链表位置
static int G_Count = 0;
//添加学生信息
void AddStu(void){
int temp_sel;
int temp_id;
char temp_name[21];
char temp_sex[3];
short temp_age;
system("cls");
printf("添加学生信息\n");
if (G_Head == NULL){
G_Current = (Student*)malloc(sizeof(struct StudentManage));
G_Head = G_Current;
printf("学号:");
scanf("%d",&temp_id);
printf("姓名:");
scanf("%s", temp_name);
printf("性别:");
scanf("%s", temp_sex);
printf("年龄:");
scanf("%hd", &temp_age);
G_Current->id = temp_id;
strcpy(G_Current->name, temp_name);
strcpy(G_Current->sex, temp_sex);
G_Current->age = temp_age;
G_Current->next = NULL;
G_Count++;
printf("1、继续添加 2、返回\n");
temp_sel = getche();
while (1){
if (temp_sel == '1' || temp_sel == '2'){
if (temp_sel == '1')break;
if (temp_sel == '2')return;
}
else{
printf("输入错误!\n");
printf("1、继续添加 2、返回\n");
temp_sel = getche();
}
}
}
while (1){
if (G_Current == NULL)return;
G_Current->next = (Student*)malloc(sizeof(struct StudentManage));
G_Current = G_Current->next;
printf("学号:");
scanf("%d", &temp_id);
printf("姓名:");
scanf("%s", temp_name);
printf("性别:");
scanf("%s", temp_sex);
printf("年龄:");
scanf("%hd", &temp_age);
G_Current->id = temp_id;
strcpy(G_Current->name, temp_name);
strcpy(G_Current->sex, temp_sex);
G_Current->age = temp_age;
G_Current->next = NULL;
G_Count++;
printf("1、继续添加 2、返回\n");
temp_sel = getche();
while (1){
if (temp_sel == '1' || temp_sel == '2'){
if (temp_sel == '1')break;
if (temp_sel == '2')return;
}
else{
printf("输入错误!\n");
printf("1、继续添加 2、返回\n");
temp_sel = getche();
}
}
}
}
//删除学生信息
void DelStu(void){
int temp_id;
int temp_sel;
Student* temp_current;
Student* temp;
system("cls");
printf("请输入要删除的学号:");
while (1){
scanf("%d", &temp_id);
temp_current = FineStu(temp_id);
if (temp_current == NULL)
printf("找不到要删除的学号!");
else{
P(temp_current);
printf("1、删除 2、返回");
temp_sel = getche();
while (1){
if (temp_sel == '1' || temp_sel == '2'){
if (temp_sel == '1'){
temp = temp_current->next;
temp_current->next = temp_current->next->next;
free(temp);
break;
}
if (temp_sel == '2')return;
}
else{
printf("输入错误!\n");
printf("1、删除 2、返回");
temp_sel = getche();
}
}
}
}
}
/*搜索学生信息 返回0为参数错误,返回NULL搜索不到id,搜索到返回当前地址的上一个地址*/
Student* FineStu(int id){
Student* temp_current = G_Head;
Student* temp;
if (id <= 0)return 0;
if (G_Head->id == id)return G_Head;
while (temp_current->next != NULL){
temp = temp_current;
if (temp_current->next->id == id){
return temp;
}
}
return NULL;
}
//排序
void Sort(void){
Student* temp_current = G_Head;
Student* temp_ptr = NULL;
for (int x = 0; x < G_Count - 1; x++){
for (int y = 0; y < G_Count - 1 - x; y++){
if (temp_current->id>temp_current->next->id){
temp_ptr = temp_current->next;
temp_current->next = temp_current;
temp_current = temp_ptr;
}
}
}
}
//打印学生信息
void P(Student* data){
if (data == NULL)return;
printf("学号:%d\n", data->id);
printf("姓名:%s\n", data->name);
printf("性别:%s\n", data->sex);
printf("年龄:%hd\n", data->age);
return;
}
//释放链表内存
void FreeStu(void){
Student* temp_current;
while (1){
if (G_Head != NULL){
temp_current = G_Head;
G_Head = G_Head->next;
free(temp_current);
}
else{
return;
}
}
}
int main(void){
AddStu();
FreeStu();
return 0;
}