left of '->next' must point to struct/union为什么?

nichothia nichothia 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这是我的一个学生成绩管理系统的创建链表记录部分 为什么编译器一直说我Student不能illegal use呢?

我明明定义了结构体Student的啊

还有为什么一直说->next左边的不是结构体呢?CurrentData也是我定义过的Student结构体指针啊

跪求解释error和warning的原因

代码如下

#include<stdlib.h>
#include<stdio.h>
#include<string.h>

struct stud
{
char Name[20];
float Score;
struct stud*next;
};
typedef struct stud Student;

Student* Create();


Student* Insert(Student*head);



void Display_Main_Menu();

int menu_select();

int Continue();





int main(int argc,char*argv[])
{

Display_Main_Menu();

for(;;)
{
switch(menu_select())
{
case 1:
printf("Execution of \"Creat List\"\n");
Create();
break;

default:
printf("error!please input 1\n");
};
}


return 0;
}

int menu_select()
{
int SelectedNumber;
printf("please input the number(from 0 to 7) and \'Enter\':");
scanf("%d",&SelectedNumber);
return SelectedNumber;
};

void Display_Main_Menu()
{
printf("1. Creat List\n");
printf("2. Display All Record\n");
printf("3. Insert a Record\n");
printf("4. Delete a Record\n");
printf("5. Query\n");
printf("6. Add Records from a Text File\n");
printf("7. Write to a Text File\n");
printf("0. Quit\n");
printf("Give your choice(0-7): ");
};

int Continue()
{
char choice;
printf("continue to input? press \'y\' or \'n\': ");
scanf("%c",&choice);
if(choice=='y')
return 1;
}

Student* Insert(Student*head)
{
Student* NewData=(struct Stud*)malloc(sizeof(struct stud));

printf("please input a name and \'Enter\': ");
scanf("%s",NewData->Name);

printf("please input the score and \'Enter\': ");
scanf("%d",&(NewData->Score));
NewData->next=NULL;

if(head==NULL)
{
head=NewData;
return head;
}

Student *CurrentData=head;

while(CurrentData->next!=NULL)
{
CurrentData=CurrentData->next;
};

CurrentData->next=NewData;

}

Student* Create()
{
static struct Student *head=NULL;
do
{
Insert(head);
printf("Insert a piece of data successfully\n");
}
while(Continue()==1);

return head;

}



warning C4133: 'initializing' : incompatible types - from 'struct Stud *' to 'struct stud *'
error C2275: 'Student' : illegal use of this type as an expression
see declaration of 'Student'
error C2065: 'CurrentData' : undeclared identifier
error C2223: left of '->next' must point to struct/union
error C2223: left of '->next' must point to struct/union
error C2223: left of '->next' must point to struct/union
warning C4133: 'function' : incompatible types - from 'struct Student *' to 'struct stud *'
warning C4133: 'return' : incompatible types - from 'struct Student *' to 'struct stud *'
执行 cl.exe 时出错.
...全文

相关推荐

评论 14
收藏 已收藏
分享
返回顶部
nichothia
C语言 70,039 成员 243,237 内容