//谢谢大家,我用动态链表的方法得到了解决
#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct Word)
struct Word
{
char letter;
struct Word *next;
};
int main()
{
struct Word *creat(void);
void print(struct Word *p);
struct Word *p;
p=creat();
print(p);
return 0;
}
struct Word *creat(void)
{
struct Word *p1,*p2,*head;
int n;
n=0;
head=NULL;
puts("Please input the array:");
p1=p2=(struct Word*)malloc(LEN);
scanf("%c",&p1->letter);
while(p1->letter!='\n')
{
n++;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct Word*)malloc(LEN);
scanf("%c",&p1->letter);
}
p2->next=NULL;
return head;
//返回一个指向表首的指针
}
void print(struct Word *p)
{
puts("the array that putted is:");
if(p!=NULL)
while(p!=NULL)
{
printf("%c",p->letter);
p=p->next;
}
else
puts("The array is NULL");
putchar('\n');
}