[求助]那位大哥大嫂幫小弟解決一下簡單鏈表問題
自己做的,總是不對,剛學結構体,做什麽錯什麽。這個程序是創建一個動態鏈表,然後輸出。但只創建了兩個節點就結束循環了。我哪裏出錯了呢?
#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof (struct student)
struct student
{
char num[11];
char name[20];
struct student *next;
};
void main()
{void print(struct student *head);
struct student *t1,*t2,*head;
head=t1=t2=NULL;
head=t2=t1=(struct student*) malloc(LEN);
scanf("%s,%s",head->num,head->name);
t1->num[10]='\0';
if (t1->num!="stop")
{
t1=t2->next=( struct student*) malloc(LEN);
scanf("%s,%s",t1->num,t1->name);
t1->num[10]='\0';
t2=t1;
}
else
t1->next=NULL;
print(head);
}
void print(struct student *head)
{
struct student *p;
printf("\nNow,these record are:\n");
p=head;
if (head!=NULL)
do
{printf("%s,%s",p->num,p->name);
p=p->next;
}
while (p!=NULL);
}