主题:我是新手!帮忙...谢!
#include<stdio.h>
#include<malloc.h>
#define NULL 0
typedef struct student
{
long num;
struct student *next;
}Link;
struct student *creat(void)
{
struct student *head,p1,p2;
p1=(Link*)malloc(sizeof(Link));
p2=(Link*)malloc(sizeof(Link));
head=NULL;
int n=0;
scanf("%ld ",&p1.num);
while(p1.num)
{
n=n+1;
if(n==1)head=p1;
else p2.next=p1;
p2=p1;
p1=(Link*)malloc(sizeof(Link));
}
p2.next=NULL;
return(head);
}
main()
{
struct student *head;
struct student *p;
head=creat();
p=head.next;
if(head)
do{
printf("%ld ",p.num);
p=p.next;
}while(p);
return 0;
}
错了p.num怎么就不对呢?
#include<malloc.h>
#define NULL 0
typedef struct student
{
long num;
struct student *next;
}Link;
struct student *creat(void)
{
struct student *head,p1,p2;
p1=(Link*)malloc(sizeof(Link));
p2=(Link*)malloc(sizeof(Link));
head=NULL;
int n=0;
scanf("%ld ",&p1.num);
while(p1.num)
{
n=n+1;
if(n==1)head=p1;
else p2.next=p1;
p2=p1;
p1=(Link*)malloc(sizeof(Link));
}
p2.next=NULL;
return(head);
}
main()
{
struct student *head;
struct student *p;
head=creat();
p=head.next;
if(head)
do{
printf("%ld ",p.num);
p=p.next;
}while(p);
return 0;
}
错了p.num怎么就不对呢?