帮忙看看这个问题出在哪里了?

doveqian 2010-07-06 09:18:52
int Input(Student stud[],int n)
{
int i=0;
char sign='y';
char x[10];
int j;
int k;
while(tolower(sign)=='y')
{
printf("\t\t\tstudent's num:");
//scanf("\t\t\t%s",stud[i].num);
k=1;
while(k!=0)
{
scanf("\t\t\t%s",stud[i].num);
if((n+i)<1)
break;
else
for(j=0;j<(n+i);j++)
{
if(strcmp(stud[i].num,stud[j].num)==0)
{
k=1;
printf("\t\t\tError:num reduplicate\n");
printf("\t\t\tplease enter again:");
break;
}
else
{
k=0;
break;
}
}
}

printf("\t\t\tstudent's name:");
scanf("\t\t\t%s",stud[n+i].name);

printf("\t\t\tstudent's score:");
scanf("\t\t\t%d",&stud[n+i].score);

gets(x);

printf("\t\t\tany more records?(Y/N)");
scanf("\t\t\t%c",&sign);
i++;
}
return(n+i);



为什么总是只能判断第一个,以后都没有判断呢?
...全文
119 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
doveqian 2010-07-06
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 auauwuwuwu 的回复:]
#include <stdio.h>

struct Student
{
char num[20];
char name[20];
int score;
};

int tolower(int i)
{
if(i>='A' && i<='Z')
return i+32;
else
return i;
}

int Input(Student st……
[/Quote]
搞定了 谢谢,那个n是学生的数目,开始为0,后面添加一次,增加一个,return (n+i)
auauwuwuwu 2010-07-06
  • 打赏
  • 举报
回复
#include <stdio.h>

struct Student
{
char num[20];
char name[20];
int score;
};

int tolower(int i)
{
if(i>='A' && i<='Z')
return i+32;
else
return i;
}

int Input(Student stud[],int n)
{
int i=0;
char sign='y';
char x[10];
int j;
int k;
while(tolower(sign)=='y')
{
printf("\t\t\tstudent's num:");
//scanf("\t\t\t%s",stud[i].num);
k=1;
while(k!=0)
{
scanf("\t\t\t%s",stud[i].num);
if((n+i)<1)
break;
else
for(j=0;j<(n+i);j++)
{
if(strcmp(stud[i].num,stud[j].num)==0)
{
k=1;
printf("\t\t\tError:num reduplicate\n");
printf("\t\t\tplease enter again:");
break;
}
else
{
k=0;
break;
}
}
}

printf("\t\t\tstudent's name:");
scanf("\t\t\t%s",stud[n+i].name);

printf("\t\t\tstudent's score:");
scanf("\t\t\t%d",&stud[n+i].score);

gets(x);

printf("\t\t\tany more records?(Y/N)");
scanf("\t\t\t%c",&sign);
i++;
}
return(n+i);
}

void main()
{
Student stud[20];
Input(stud,0) ;
}


怎么我的可以录入多个呢?你是不是想实现从 结构体数组stud中的第n个数据 开始录入学生信息的?。。 如果你只能录入一个的话 你看看你的tolower()函数是不是返回了需要用的值!。。
doveqian 2010-07-06
  • 打赏
  • 举报
回复
找到了,后面的else的break多余,谢谢
doveqian 2010-07-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 mgsuzic 的回复:]
跳出单次循环用continue,你是不是滥用break造成的呀~
[/Quote]

我的原意是:本次输入sutd.num判断有没有重复,当然要用break跳出找到一样的num了,再循环没意义了!
doveqian 2010-07-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 mgsuzic 的回复:]
没怎么具体看,但这个写法很是奇怪,scanf("\t\t\t%s",stud[i].num);
难道你输入前,还要按下三个tab,再输入数据~.....
[/Quote]

你弄错了吧,我那个[\t]是对齐格式用到的
Mg 2010-07-06
  • 打赏
  • 举报
回复
跳出单次循环用continue,你是不是滥用break造成的呀~
Mg 2010-07-06
  • 打赏
  • 举报
回复
没怎么具体看,但这个写法很是奇怪,scanf("\t\t\t%s",stud[i].num);
难道你输入前,还要按下三个tab,再输入数据~.....

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧