C语言链表的基本问题
现在还不会链表啊,按着书上的看了遍,对着写了遍,就是编译不了,和书本上一样的。。#include<stdio.h>#include<string.h>#include<m...
现在还不会链表啊,按着书上的看了遍,对着写了遍,就是编译不了,和书本上一样的。。
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#define N 3
#define LEN sizeof(struct grade)
struct grade
{
char no[7];
int score;
struct grade*next;
};
struct grade*create(void)
{
struct great*head=NULL,*new,*tail;
for(int i=1;i<=N;i++)
{
new=(struct grade *)malloc(LEN);
scanf("%s",new->no);
if(strcmp(new->no,"000000")==0)
{
free(new);
break;
}
scanf("%d",&new->score);
new->next=NULL;
if(i==1)head=new;
else tail->next=new;
tail=new;
}
return head;
}
int main()
{
struct grade*p;
int i;
p=create();
if(p!=NULL)
for(i=1;i<=N;i++)
{
printf("%s:%d\n",p->no,p->score);
p=p->next;
}
} 展开
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#define N 3
#define LEN sizeof(struct grade)
struct grade
{
char no[7];
int score;
struct grade*next;
};
struct grade*create(void)
{
struct great*head=NULL,*new,*tail;
for(int i=1;i<=N;i++)
{
new=(struct grade *)malloc(LEN);
scanf("%s",new->no);
if(strcmp(new->no,"000000")==0)
{
free(new);
break;
}
scanf("%d",&new->score);
new->next=NULL;
if(i==1)head=new;
else tail->next=new;
tail=new;
}
return head;
}
int main()
{
struct grade*p;
int i;
p=create();
if(p!=NULL)
for(i=1;i<=N;i++)
{
printf("%s:%d\n",p->no,p->score);
p=p->next;
}
} 展开
2个回答
展开全部
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#define N 3
#define LEN sizeof(struct grade)
struct grade
{
char no[7];
int score;
struct grade*next;
};
struct grade*create(void)
{
//grade打错了
struct grade *head=NULL,*new,*tail;
for(int i=1;i<=N;i++)
{
new=(struct grade *)malloc(LEN);
scanf("%s",new->no);
if(strcmp(new->no,"000000")==0)
{
free(new);
break;
}
scanf("%d",&new->score);
new->next=NULL;
if(i==1)
head=new;
else tail->next=new;
tail=new;
}
return head;
}
int main()
{
struct grade*p;
int i;
p=create();
if(p!=NULL)
//for(i=1;i<=N;i++)
//注意这里的不同
for(i=1;p&&i<=N;i++)
{
printf("%s:%d\n",p->no,p->score);
p=p->next;
}
}
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#define N 3
#define LEN sizeof(struct grade)
struct grade
{
char no[7];
int score;
struct grade*next;
};
struct grade*create(void)
{
//grade打错了
struct grade *head=NULL,*new,*tail;
for(int i=1;i<=N;i++)
{
new=(struct grade *)malloc(LEN);
scanf("%s",new->no);
if(strcmp(new->no,"000000")==0)
{
free(new);
break;
}
scanf("%d",&new->score);
new->next=NULL;
if(i==1)
head=new;
else tail->next=new;
tail=new;
}
return head;
}
int main()
{
struct grade*p;
int i;
p=create();
if(p!=NULL)
//for(i=1;i<=N;i++)
//注意这里的不同
for(i=1;p&&i<=N;i++)
{
printf("%s:%d\n",p->no,p->score);
p=p->next;
}
}
追问
编译还是错了。。13个错误。。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询