我实在改不出来.
不过自己写了一个弥补自己的过失吧.呵呵.....
#define NULL 0
#include<stdio.h>
#include <string.h>
#include <malloc.h>
struct num
{
char ch;
struct num *next;
};
//初始化
struct num *initlist()
{
struct num *head;
head=(struct num *)malloc(sizeof(struct num));
head->next=NULL;
return head;
}
struct num *creat(struct num *head)//建表
{
struct num *p,*q;
char ch;
p=head;
puts("please input the original string:");
ch=getchar();
while(ch!='\n')
{
q=(struct num *)malloc(sizeof(struct num));
q->ch=ch;
q->next=NULL;
p->next=q;
p=q;
ch=getchar();
}
return head;
}
struct num *insert(struct num *head)//插入空格
{
struct num *p,*q;
q=head->next;
while (q!=NULL)
{
p=(struct num *)malloc(sizeof(struct num));
p->ch=' ';
p->next=q->next;
q->next=p;
q=q->next->next;
}
return head;
}
void display(struct num *head)//打印
{
struct num *p;
p=head->next;
while (p)
{
printf("%c",p->ch);
p=p->next;
}
}
int main(void)
{
struct num *head;
head=initlist();
head=creat(head);
head=insert(head);
display(head);
printf("\n");
return 0;
}