C语言求救无限死循环

来源:百度知道 编辑:UC知道 时间:2024/09/21 17:42:10
TEST-num one(1053810913) 14:55:31
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
/*定义结构点结构*/
struct studentstruct
{

unsigned int number; //编号
unsigned char Name[200]; //姓名
unsigned char Sex; //性别
double birthday; //生日
double year; //年
double month; //月
double day; //日
unsigned int homeplace; //籍贯
unsigned char education; //学历
unsigned char address; //地址
double telephone; //电话
double gongling; //工龄
double emolument; //薪水
unsigned char quit; //退出
struct studentstruct *Next;
};
struct studentstruct *create(void)
{
struct studentstruct *Head=NULL,*New,*Tail;
int count=0; /*链表中的结点个数(初始化0)*/
for ( ; ; ) /*缺省3个表达式的for语句*/
{
/*申请一个新的结点的空间*/
if ((New=(struct studentstruct*)malloc(sizeof(struct studentstruct)))==NULL)
return NULL;

代码太乱。没太怎么看。你定义的结构体中的quit有问题。
unsigned char quit; //退出
不应该用char吧。你这样子就算输入0。那么ascii码对应的值是48
必然结束不了。
你改成int试试。
或者在读入New->quit时改一下,你这里用的是
scanf("%c",&New->quit);
改成
scanf("%d",&New->quit);

如果有什么问题可以加我百度HI。

楼上说的有问题。scanf就算不处理回车符也是一样的。因为后续都是用scanf来完成输入的。除非有getchar这类的读取字符。才需要处理换行符之类的

回车符没考虑吧,注意屏蔽每次输入的时候的回车符

quit 有问题
改成int型
或者
new->quit == '0'
这样试试
后一种方法可能要在录入quit前加个getchar()
当然喽,最好用cin来输入比较好些

把create函数也用do while就可以退出死循环了。
struct studentstruct *create(void)
{
struct studentstruct *Head=NULL,*New,*Tail;
int count=0; /*链表中的结点个数(初始化0)*/
do /*缺省3个表达式的for语句*/
{
/*申请一个新的结点的空间*/
if ((New=(struct studentstruct*)malloc(sizeof(struct studentstruct)))==NULL)
return NULL;
/*输入结点数据与的各数据项*/
printf("请输入第%d个软件测试工程师的信息:\n",count+1);
printf("工程师的编号:");<