->num' must point to class/struct/union请问哪里出错了

ZuooMingo 2012-10-13 10:03:42
--------------------Configuration: xx - Win32 Debug--------------------
Compiling...
xx.cpp
C:\Documents and Settings\Administrator\桌面\xx.cpp(19) : error C2027: use of undefined type 'Student'
C:\Documents and Settings\Administrator\桌面\xx.cpp(9) : see declaration of 'Student'
C:\Documents and Settings\Administrator\桌面\xx.cpp(20) : error C2065: 'sanf' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\xx.cpp(20) : error C2027: use of undefined type 'Student'
C:\Documents and Settings\Administrator\桌面\xx.cpp(9) : see declaration of 'Student'
C:\Documents and Settings\Administrator\桌面\xx.cpp(20) : error C2227: left of '->num' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\xx.cpp(20) : error C2027: use of undefined type 'Student'
C:\Documents and Settings\Administrator\桌面\xx.cpp(9) : see declaration of 'Student'
C:\Documents and Settings\Administrator\桌面\xx.cpp(20) : error C2227: left of '->score' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\xx.cpp(22) : error C2027: use of undefined type 'Student'
C:\Documents and Settings\Administrator\桌面\xx.cpp(9) : see declaration of 'Student'
C:\Documents and Settings\Administrator\桌面\xx.cpp(22) : error C2227: left of '->num' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\xx.cpp(22) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.

xx.exe - 1 error(s), 0 warning(s)





# include <stdio.h>
# include <malloc.h>
# define LEN sizeof(struct Student)

struct Srudent
{
long num;
float score;
struct Student *next;
};

int n;

struct Student * creat()
{
struct student * head;
struct Student *p1, *p2;
n = 0;
p1=p2=( struct Student * )malloc(LEN);
sanf("%ld, %f", &p1->num, &p1->score);
head=NULL;
while(p1 -> num!=0)
{

n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct Student * )malloc(LEN);
scanf("%ld, %f", &p1->num, &p1->score);

}
p2->next=NULL;
return(head);

}
void prin(struct Student head)
{
struct Student * p;
pintf("\nNow,These %d records are:\n", n);
p=head;
if(head!==NULL)
do
printf("%ld %5.1f\n",p->num,p->score);
p=p->next;
while(p!=NULL);
}
void main()
{
struct Student * head;
head=creat();
prin(head);
}
请教一下大家

...全文
407 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
L_chxu 2012-10-13
  • 打赏
  • 举报
回复
LZ犯了很多小错误,以后应该注意下

修改如下:


# include <stdio.h>
# include <malloc.h>
# define LEN sizeof(struct Student)

struct Student// 不是Srudent
{
long num;
float score;
struct Student *next;
};

int n;

struct Student * creat()
{
struct Student * head;//Studnet 中的S要大写
struct Student *p1, *p2;
n = 0;
p1=p2=( struct Student * )malloc(LEN);
scanf("%ld, %f", &p1->num, &p1->score);//scanf
head=NULL;
while(p1 -> num!=0)
{

n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct Student * )malloc(LEN);
scanf("%ld, %f", &p1->num, &p1->score);

}
p2->next=NULL;
return(head);

}

void prin(struct Student *head) //此处head应该为指针
{
struct Student *p;
printf("\nNow,These %d records are:\n", n);// printf
p=head;
if(head!=NULL)// !=只有一个=
do //代码块应用{}
{
printf("%ld %5.1f\n",p->num,p->score);
p=p->next;
} while(p!=NULL);
}
void main()
{
struct Student *head;
head=creat();
prin(head);
}
armsword 2012-10-13
  • 打赏
  • 举报
回复
Student
armsword 2012-10-13
  • 打赏
  • 举报
回复

struct Srudent //student
newtee 2012-10-13
  • 打赏
  • 举报
回复
struct Srudent

70,020

社区成员

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

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