请高手们看看哪里出错了

ZuooMingo 2012-10-13 10:38:17
# include <stdio.h>
# include <malloc.h>
# define LEN sizeof(struct Student)

struct Student
{
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 print(struct Student head)
{
struct Student * p;
printf("\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();
print(head);
}











--------------------Configuration: xx - Win32 Debug--------------------
Compiling...
xx.cpp
C:\Documents and Settings\Administrator\桌面\xx.cpp(20) : error C2065: 'sanf' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\xx.cpp(27) : error C2440: '=' : cannot convert from 'struct Student *' to 'struct creat::student *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\xx.cpp(36) : error C2440: 'return' : cannot convert from 'struct creat::student *' to 'struct Student *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\xx.cpp(43) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct Student' (or there is no acceptable conversion)
C:\Documents and Settings\Administrator\桌面\xx.cpp(44) : error C2059: syntax error : '='
C:\Documents and Settings\Administrator\桌面\xx.cpp(54) : error C2664: 'print' : cannot convert parameter 1 from 'struct Student *' to 'struct Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
执行 cl.exe 时出错.

xx.exe - 1 error(s), 0 warning(s)
...全文
177 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ZuooMingo 2012-10-14
  • 打赏
  • 举报
回复
--------------------Configuration: 链表 - Win32 Debug--------------------
Compiling...
链表.cpp
C:\Documents and Settings\Administrator\桌面\链表.cpp(1) : error C2143: syntax error : missing ';' before '/'
C:\Documents and Settings\Administrator\桌面\链表.cpp(1) : error C2501: 'C' : missing storage-class or type specifiers
C:\Documents and Settings\Administrator\桌面\链表.cpp(1) : error C2143: syntax error : missing ';' before '/'
C:\Documents and Settings\Administrator\桌面\链表.cpp(1) : error C2014: preprocessor command must start as first nonwhite space
e:\vc++\vc++6.0中文绿色版\vc++6.0中文绿色版\vc98\include\malloc.h(36) : error C2143: syntax error : missing ';' before '{'
e:\vc++\vc++6.0中文绿色版\vc++6.0中文绿色版\vc98\include\malloc.h(36) : error C2447: missing function header (old-style formal list?)
C:\Documents and Settings\Administrator\桌面\链表.cpp(19) : error C2065: 'malloc' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\链表.cpp(20) : error C2065: 'scanf' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\链表.cpp(21) : error C2065: 'NULL' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\链表.cpp(21) : error C2440: '=' : cannot convert from 'int' to 'struct Student *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\链表.cpp(35) : error C2440: '=' : cannot convert from 'int' to 'struct Student *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\链表.cpp(42) : error C2065: 'printf' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\链表.cpp(44) : error C2446: '!=' : no conversion from 'int' to 'struct Student *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\链表.cpp(44) : error C2040: '!=' : 'struct Student *' differs in levels of indirection from 'int'
C:\Documents and Settings\Administrator\桌面\链表.cpp(50) : error C2446: '!=' : no conversion from 'int' to 'struct Student *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\链表.cpp(50) : error C2040: '!=' : 'struct Student *' differs in levels of indirection from 'int'
执行 cl.exe 时出错.

链表.obj - 1 error(s), 0 warning(s)



错误更多了。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
非常郁闷中。。。。。。。。。。。。。。。。。。
ZuooMingo 2012-10-14
  • 打赏
  • 举报
回复
哈哈谢谢!实在太感谢大家了,第一次打出程序来不太会弄
newtee 2012-10-13
  • 打赏
  • 举报
回复
你上个帖子人家把源程序调好给你了
Mr_defy_L 2012-10-13
  • 打赏
  • 举报
回复
# include <stdio.h>
# include <malloc.h>
# define LEN sizeof(struct Student)

struct Student
{
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);
scanf("%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 print(struct Student *head)
{
struct Student *p;
printf("\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();
print(head);
}

armsword 2012-10-13
  • 打赏
  • 举报
回复
那个自己学学debug能力吧。

下面有提示错误的。
armsword 2012-10-13
  • 打赏
  • 举报
回复
sanf //scanf

student 改成Student
newtee 2012-10-13
  • 打赏
  • 举报
回复
浪费了自己的时间也浪费了别人时间 自己慢慢Debug吧
newtee 2012-10-13
  • 打赏
  • 举报
回复
sanf("%ld, %f", &p1->num, &p1->score); 不想说什么
scanf
上面都写的很清楚

69,371

社区成员

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

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