c语言链表问题
出现了三个问题,求帮忙解决error:cannotconvert`Student'to`Student*'inassignmenterror:nomatchfor'ope...
出现了三个问题,求帮忙解决
error: cannot convert `Student' to `Student*' in assignment
error: no match for 'operator!=' in 'head != 0'
error: conversion from `Student*' to non-scalar type `Student' requested
构建中止 未命名32: 3 个错误, 0 个警告
#include <stdio.h>
#include <stdlib.h>
#define LEN sizeof(struct Student)
struct Student
{
long num;
float score;
struct Student*next;
} ;
int n;
struct Student*creat(void)
{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");
p=head;
if(head!=NULL)
do
{
printf("%ld%5.2f\n",p->num,p->score);
p=p->next;
}
while(p=NULL);
}
int main()
{
struct Student*head;
head=creat();
print(head);
// printf("\nnum:%ld\nscore:%5.2f\n",pt->num,pt->score);
return 0;
} 展开
error: cannot convert `Student' to `Student*' in assignment
error: no match for 'operator!=' in 'head != 0'
error: conversion from `Student*' to non-scalar type `Student' requested
构建中止 未命名32: 3 个错误, 0 个警告
#include <stdio.h>
#include <stdlib.h>
#define LEN sizeof(struct Student)
struct Student
{
long num;
float score;
struct Student*next;
} ;
int n;
struct Student*creat(void)
{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");
p=head;
if(head!=NULL)
do
{
printf("%ld%5.2f\n",p->num,p->score);
p=p->next;
}
while(p=NULL);
}
int main()
{
struct Student*head;
head=creat();
print(head);
// printf("\nnum:%ld\nscore:%5.2f\n",pt->num,pt->score);
return 0;
} 展开
3个回答
展开全部
加空格
struct Student*head;
struct Student *head;
struct Student*p;
struct Student *p; 你的明白?
感觉你是复制的
而且。。
struct Student*head;
struct Student *head;
struct Student*p;
struct Student *p; 你的明白?
感觉你是复制的
而且。。
追问
如果我说是我一点一点打出来的你会信吗?刚开始有20多个错误你又怎么会知道?我就想问你真的看得懂吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
s/void print(struct Student head)/void print(struct Student *head)
参数少了一个 "*"
参数少了一个 "*"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询