主题:[原创]这个程序的问题??
#include <stdio.h>
#include <stdlib.h>
typedef struct student
{
int no;
float score;
struct student *next;
}Student;
void main()
{
Student *p,*q,*head;
p=(Student *)malloc(sizeof(Student));
q=(Student *)malloc (sizeof(Student));
scanf("%d,%f",&p->no,&p->score);
scanf("%d,%f",&q->no,&q->score);
p->next=q;
q->next=NULL;
head=p;
while(p!=NULL)
{
printf("%d,%f",p->no ,p->score);
p=p->next;
}
p=head;
while(p!=NULL)
{
q=p;
p=p->next;
free(q);
}
}
为什么输入的不是想的那样的啊???
#include <stdlib.h>
typedef struct student
{
int no;
float score;
struct student *next;
}Student;
void main()
{
Student *p,*q,*head;
p=(Student *)malloc(sizeof(Student));
q=(Student *)malloc (sizeof(Student));
scanf("%d,%f",&p->no,&p->score);
scanf("%d,%f",&q->no,&q->score);
p->next=q;
q->next=NULL;
head=p;
while(p!=NULL)
{
printf("%d,%f",p->no ,p->score);
p=p->next;
}
p=head;
while(p!=NULL)
{
q=p;
p=p->next;
free(q);
}
}
为什么输入的不是想的那样的啊???