c语言间接级别不同_间接寻址不同问题?求解决!

这篇博客介绍了C语言实现链表数据结构的操作,包括添加学生信息、删除学生信息、查找学生信息(FineStu 函数)、排序及释放链表内存的函数。在删除过程中遇到了间接寻址级别的错误,需要调整类型匹配来解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

错误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;

}

59784254bcb08d1660658539e3aaff5e.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值