当前位置: 代码迷 >> C语言 >> 大家帮我看看错在那里了啊!
  详细解决方案

大家帮我看看错在那里了啊!

热度:135   发布时间:2008-05-03 09:52:25.0
大家帮我看看错在那里了啊!
/* Note:Your choice is C IDE */
#include "stdio.h"
#include<malloc.h>
typedef struct node
{
    char ch;
    struct node *next;
}linkstr;
linkstr *creat(char *ch)
{
    linkstr *p,*head,*q;
    int i=0;
    p=head=(linkstr *)malloc(sizeof(linkstr));
    head->next=NULL;
    while(ch[i]!=0)
    {
        q=(linkstr *)malloc(sizeof(linkstr));
        p->ch=ch[i];
        p->next=q;
        q->next=NULL;
        p=q;i++;
    }
    return head;
}
void output(linkstr *head)
{
    linkstr *p;
    p=head->next;
    while(p)
    {
        printf("%c",p->ch);
        p=p->next;
    }
}
void main()
{
    linkstr *head;
    int i;char str;
    head=(linkstr *)malloc(sizeof(linkstr));
    for(i=0;i<10;i++)
    {
        scanf("%c",&str);
        head=creat(&str);
    }
    output(head);
}

[[it] 本帖最后由 wangyinshiwo 于 2008-5-8 14:10 编辑 [/it]]

[[it] 本帖最后由 wangyinshiwo 于 2008-7-20 20:50 编辑 [/it]]
搜索更多相关的解决方案: linkstr  next  head  node  malloc  

----------------解决方案--------------------------------------------------------
  相关解决方案