才看数据结构,函数之间不会建立

作者在 2010-09-27 22:56:18 发布以下内容
#include <stdio.h>
#include <malloc.h>
typedef char  datetype;
typedef struct
{
 datetype date;
  struct node *next;
}listnode;
typedef  listnode  *linklist;
listnode  *p;
linklist  head;
listnode creatnode();
void outnode(listnode *head);
void main()
{
creatnode( );
outnode( head);

}
listnode creatnode()
{
 char ch;
 int flag=1;
 listnode *p;
 head=NULL;
 printf("\n请输入数据,当输入#时,输入停止");
 while(ch=getchar())
 {
  if(ch != '#')
  {
 p=(listnode* )malloc(sizeof(listnode));
 p->date=ch;
 p->next=head;
 head=p;
  }
  else
   flag=0;
 }
 return (head);
}
void outnode(listnode *head)
{
 listnode *p;
 p=head;
 while(p->next != NULL)
 {
  printf("\n%s",p->date );
  free(p);
  p=p->next;
 }
}
 
默认分类 | 阅读 667 次
文章评论,共0条
游客请输入验证码
浏览10600次
最新评论