- #include"stdio.h"
- #include"malloc.h"
- typedefstructNode
- {chardata;
- structNode*next;
- }Node,*Linklist;
- voidInput(Linklist&p)//输入函数
- {Node*r,*s;
- r=p;
- charc;
- intflag=1;
- while(flag)//标记
- {c=getchar();//读入字符
- if(c!='#')
- {
- s=(Node*)malloc(sizeof(Node));//动态分配空间
- s->data=c;//将读入的字符存储在s中
- r->next=s;
- r=s;
- }
- else
- {flag=0;//当输入的字符为#时结束循环
- r->next=NULL;//将尾指针设置为空
- }
- }
- }
- voidOutput(Linklist&p)//输出函数
- {
- LinklistL;
- L=p->next;
- while(L)//当L不为空
- {
- printf("%c",L->data);
- L=L->next;
- }
- }
- voidmain()
- {Linklistp;//定义变量
- p=(Node*)malloc(sizeof(Node));//初始化
- Input(p);//输入
- Output(p);//输出
- }
本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/817857