下面这个数据结构中c程序疑问,请高手帮忙!!
typedef struct node
{char data;
struct node *next;
}node,*nodeptr;
#define len sizeof(node)
nodeptr creatlink()
{nodeptr l,p,q;
int i,n;
char e;
l=(nodeptr)malloc(len);
l->next=0;
q=l;
printf(“\ninput the length of the list:”);
scanf(“%d”,&n);
printf(“\ninput the numbers:”);
for(i=1;i<=n;i++)
{p=(nodeptr)malloc(len);
scanf(“%c”,&e);
p->data=e;
q->next=p;
q=p;
}
q->next=0;
return l;
}
int length(nodeptr l)
{nodeptr p ; int i=0;
p=l->next;
while(p)
{ i++; p=p->next;}
return i;
}
main()
{ nodeptr l,p;
int n;
l=creatlink();
printf(“\nthe numbers before are:”);
p=l->next;
while(p)
{printf(“%d,”,p->data);
p=p->next;
}
n=length(l); printf(“\n%d”,n);
}
TC中输出为
input the length of the list:4
input the numbers:aaa
the numbers before are:10,97,97,97,
4
为什么输出的第一是10???请指教
>> 本文固定链接: http://www.vcgood.com/archives/2806
请高手指点一下啊!!!!!!!!!
急!!!!!!!!!!