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

nichothia 2010-06-05 11:01:32
这是我的一个学生成绩管理系统的创建链表记录部分 为什么编译器一直说我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 时出错.
...全文
1749 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
nichothia 2010-06-06
  • 打赏
  • 举报
回复
好吧 是我说的有歧义 可是 你能帮我把这个问题解决了么、、、?
yzx714 2010-06-06
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 nichothia 的回复:]
这是我的一个学生成绩管理系统
[/Quote]你这句话实在太让人误解了。。。
huanmie_09 2010-06-05
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 nichothia 的回复:]
多谢二楼指点 但是我全都修改成 Student后

C# code

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

struct stud
{
char Name[20];
float Score;
struct stud*next;
};
typedef struct stu……
[/Quote]
Student* Insert(Student*head)
{
Student* NewData=(Student*)malloc(sizeof(Student));

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;
把红色那一句移动到
Student* Insert(Student*head)
{
Student* NewData=(Student*)malloc(sizeof(Student));
这里就ok了.
c编译器的原因,变量声明放在前面.
或者改成.cpp文件也可以.
pengzhixi 2010-06-05
  • 打赏
  • 举报
回复
我这编译OK了
nichothia 2010-06-05
  • 打赏
  • 举报
回复
多谢二楼指点 但是我全都修改成 Student后

#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 0-5\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=(Student*)malloc(sizeof(Student));

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 Student *head=NULL;
do
{
Insert(head);
printf("Insert a piece of data successfully\n");
}
while(Continue()==1);

return head;

}



还是有

这些错误 为什么呢?
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
nichothia 2010-06-05
  • 打赏
  • 举报
回复
4楼说的在理!
Walf_ghoul 2010-06-05
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 kbtyanhuo 的回复:]
若你真是老师,请不要用“跪”字
大家都是从学生过来的,看到老师这样,会伤心...
[/Quote]
只不过一个学生成绩管理系统而已,用不着这样吧...(又不是老师,汗)
KBTyanhuo 2010-06-05
  • 打赏
  • 举报
回复
若你真是老师,请不要用“跪”字
大家都是从学生过来的,看到老师这样,会伤心...
huanmie_09 2010-06-05
  • 打赏
  • 举报
回复
Student* Insert(Student*head)
{
Student* NewData=(struct Stud*)malloc(sizeof(struct stud));
注意大小写.

Student* Create()
{
static struct Student *head=NULL;

typedef struct stud Student;
这样定义了结构体的同义词后,要么用struct stud, 要么用Student来表示结构体类型.
pengzhixi 2010-06-05
  • 打赏
  • 举报
回复


Student* Insert(Student*head)
{
Student* NewData=(Student*)malloc(sizeof(Student));//mark

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 Student *head=NULL;//mark
do
{
Insert(head);
printf("Insert a piece of data successfully\n");
}
while(Continue()==1);

return head;

}
nichothia 2010-06-05
  • 打赏
  • 举报
回复
汗 我是学生好不好。。。我在帮我同学做C语言的课程设计 从没写过链表边看书编写的 OK??
难道写个学生成绩管理的程序就是老师? 就你这个逻辑也能在这里帮别人解决问题?????
yzx714 2010-06-05
  • 打赏
  • 举报
回复
引用我小学老师的一句话送给楼主:
你眼睛焊桐子壳了???
作为老师,你真失败
cattycat 2010-06-05
  • 打赏
  • 举报
回复
typedef struct stud
{
char Name[20];
float Score;
struct stud*next;
}Student;

把你的结构体定义改一下吧
nichothia 2010-06-05
  • 打赏
  • 举报
回复


#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 0-5\n");
};
}


return 0;
}

int menu_select()
{
int SelectedNumber;
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=(Student*)malloc(sizeof(Student));
Student *CurrentData=head;

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;
}


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

CurrentData->next=NewData;
return head;

}

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

return head;

}


根据8楼的提议改好了 虽然编译没错误了有个
warning C4715: 'Continue' : not all control paths return a value
但是运行后Insert了一条记录后 程序直接重复Insert函数 而跳过continue to input? press y or n:的判断 为什么呢?

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧