| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 563 人关注过本帖
标题:程序运行时怎么只能输入一条记录,就停住了。帮忙看看
只看楼主 加入收藏
陈威
Rank: 1
等 级:新手上路
帖 子:114
专家分:0
注 册:2009-10-18
结帖率:95%
收藏
 问题点数:0 回复次数:2 
程序运行时怎么只能输入一条记录,就停住了。帮忙看看
#include "stdio.h"
#include "conio.h"
#define NULL 0
#define LEN sizeof(struct student)

struct student
{char num[6];
 char name[8];
 struct student *next;
};

struct student *creat(void)
{struct student *p1,*p2,*head;
 int n=0;
 p1=p2=(struct student *)malloc(LEN);
 head=NULL;
 printf("Input 0 to end.\n");
 printf("Input num,name:\n");
 scanf("%s,%s",&p1->num,&p1->name);
 while(p1!=NULL)
 {if(n==0)head=p1;
  else p2->next=p1;
  n++;
  p2=p1;
 }
 p2->next=NULL;
 return(head);
}

void print(struct student *p)
{while(p!=NULL)
 {printf("%4s,%4s",p->num,p->name);
  p=p->next;
 }
}
main()
{struct student *ha,*hb;
 ha=creat();
 hb=creat();
 print(ha);
    getch();
}
程序运行时怎么只能输入一条记录,就停住了。
搜索更多相关主题的帖子: 运行 输入 记录 
2010-02-04 03:50
陈威
Rank: 1
等 级:新手上路
帖 子:114
专家分:0
注 册:2009-10-18
收藏
得分:0 
#include "stdio.h"
#include "conio.h"
#define NULL 0
#define LEN sizeof(struct student)

struct student
{char num[6];
char name[8];
struct student *next;
};

struct student *creat(void)
{struct student *p1,*p2,*head;
int n=0;
p1=p2=(struct student *)malloc(LEN);
head=NULL;
printf("Input 0 to end.\n");
printf("Input num,name:\n");
scanf("%s,%s",&p1->num,&p1->name);
while(p1!=NULL)
{if(n==0)head=p1;
  else p2->next=p1;
  n++;
  p1=(struct student *)malloc(LEN);
  scanf("%s,%s",&p1->num,&p1->name);

  p2=p1;
}
p2->next=NULL;
return(head);
}

void print(struct student *p)
{while(p!=NULL)
{printf("%4s,%4s",p->num,p->name);
  p=p->next;
}
}
main()
{struct student *ha,*hb;
ha=creat();
hb=creat();
print(ha);
    getch();
}
2010-02-04 05:40
陈威
Rank: 1
等 级:新手上路
帖 子:114
专家分:0
注 册:2009-10-18
收藏
得分:0 
上面程序运行怎么,没法结束。帮忙看看,谢谢。
2010-02-04 05:43
快速回复:程序运行时怎么只能输入一条记录,就停住了。帮忙看看
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017702 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved