一个关于链表的小问题
											我的问题是:我在creat函数里明明已经返回了一个地址head,然后在主函数中调用时,应该是已经将head的值赋值给p了的,但是主函数里的printf却输不出任何结果,各位高手来帮看看吧。PS:下面这段代码我自己看了半天了,还是找不出问题所在,代码写得很乱,但还是希望高手们指点一下吧。
 程序代码:
程序代码:#include<stdio.h>
#include<malloc.h>
#define NULLL 0
struct aa
{
    char a;
    struct aa *next;
};
struct aa *creat( int n)
{
    struct aa *p1=NULLL,*p2=NULLL,*head=NULLL;
    int m=1;
    while(1)
    {
        if(m==1&&m<n)
        {
            p2=(struct aa *)malloc(sizeof(struct aa));
            head=p2;
            p1=p2;
            printf("input the %dth characters: ",m);
            scanf("%c",&p1->a);    
            m+=1;
        }
        if(m!=1&&m<n)
        {
            p2=(struct aa *)malloc(sizeof(struct aa));
            p1->next=p2;
            p1=p2;
            printf("input the %dth characters: ",m);
            scanf("%c",&p1->a);
            m+=1;
        }
        if(m==n)
        {
            p2=(struct aa *)malloc(sizeof(struct aa));
            p1->next=p2;
            p2->next=NULLL;
            scanf("%c",&p2->a);
            break;
        }
    }
    return(head);  /*返回链表的起始地址head*/
}
int main()
{
    int n;
    struct aa *p;
    printf("please input the number of characters that you want: ");
    scanf("%d",&n);
    p=creat(n);
    while(1)
    {
        printf("(%c)",p->a);
        p=p->next;
        if(p->next==NULLL)
            break;
    }
    getch();
}
[ 本帖最后由 将是高手 于 2011-11-19 14:14 编辑 ]



 
											





 
	    

 
	
 谢谢了,解决了!
谢谢了,解决了!										
					
	
 没人么,来告诉我吧,这个问题困扰我很久了
没人么,来告诉我吧,这个问题困扰我很久了										
					
	