这个哪里有错 ????

来源:百度知道 编辑:UC知道 时间:2024/04/30 04:02:46
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student_node
{
int num;
char name[20];
int score;
struct student_node *next;
};
void main()
{
struct student_node *head,*tail,*p;
int num,score;
char name[20];
int size=sizeof(struct student_node);
head=tail=NULL;
printf("Input num,name and score:\n");
scanf("%d",&num);

//建立单向链表
while(num!=0)
{
p=(struct student_node*)malloc(size);
scanf("%s%d",name,&score);
p->num=num;
strcpy(p->name,name);
p->score=score;
p->next=NULL;
tail->next=p;
tail=p;
scanf("%d",&num);
}

//输出链表
for(p=head;p->next!=NULL;p=p->next)
printf("%d%s%d\n",p->num,p->name,p->score);

printf("%d\n",sizeof(float));

非常容易啊!

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

struct student_node
{
int num;
char name[20];
int score;
struct student_node *next;
};

void main()
{
struct student_node *head,*tail,*p;
int num,score;
char name[20];
int size=sizeof(struct student_node);

head=tail=NULL;
printf("Input num,name and score:\n");
scanf("%d",&num);

//建立单向链表
while(num!=0)
{
p=(struct student_node*)malloc(size);
scanf("%s%d",name,&score);
p->num=num;
strcpy(p->name,name);
p->score=score;
p->next=NULL;

if(tail==NULL)//////////////////////添加的
{
head=p;//////////////////////添加的
tail=p;//////////////////////添加的
}
else//////////////////////添加的
{//////////////////////添加的
tail->next=p;
ta