void inpstat(struct Student *pstu)
{
int i;
for(i=0;i<N;i++)
{
printf("输入第%d位学生数据:\nname\tNo.\tsex\tCpp\tEnglish\tMath\tPhysics\n",i+1);
scanf("%s%d%c%d%d%d%d",&pstu->num,&pstu->sex,&pstu->Cpp,&pstu->English,&pstu->Math,&pstu->Physics);
pstu++;
}
}
这个是函数。N=5
运行结果是这个,第3、5位学生数据输入直接被跳过去了。
你这个本来就不对应,输入的是7个,但scanf里面才6个应该是漏了pstu->name吧
而且,一个字符不能这样输入,%c输入的只是pstu->num后面的那个空格,而不是M
应该在%c前面加个空格,输入时也是输入一个空格,改成
scanf("%s%d %c%d%d%d%d", pstu->name, &pstu->num,&pstu->sex,&pstu->Cpp,&pstu->English,&pstu->Math,&pstu->Physics);
而且,一个字符不能这样输入,%c输入的只是pstu->num后面的那个空格,而不是M
应该在%c前面加个空格,输入时也是输入一个空格,改成
scanf("%s%d %c%d%d%d%d", pstu->name, &pstu->num,&pstu->sex,&pstu->Cpp,&pstu->English,&pstu->Math,&pstu->Physics);
温馨提示:答案为网友推荐,仅供参考
第1个回答 2012-07-05
pstu->num是字符数组吧?不需要加上&
建议输入完一条记录之后,加上ffush(stdin);来清空键盘缓冲区追问
建议输入完一条记录之后,加上ffush(stdin);来清空键盘缓冲区追问
num是int型变量,不是字符数组。
另外我一个数据一个数据的输入会出现这个情况
第2个回答 2012-07-05
printf("输入第%d位学生数据:\nname\tNo.\tsex\tCpp\tEnglish\tMath\tPhysics\n");
第3个回答 2012-07-05
scanf("%s%d%c%d%d%d%d",&pstu->num,&pstu->sex,&pstu->Cpp,&pstu->English,&pstu->Math,&pstu->Physics);
缺少参数,输入学生名字的参数没有。
缺少参数,输入学生名字的参数没有。
第4个回答 2012-07-05
亲 我没运行 不过有发生这个问题 应该是scanf %s %c %d混用的问题
不过你的代码中 明显在scanf里面的数量对不上 前面你应该多打了个%d
不过你的代码中 明显在scanf里面的数量对不上 前面你应该多打了个%d