本人用C语言编程,可是出现了一运行就停止工作。怎么回事,求大腿们帮帮眼看看哪里出问题啦。。。

#include<stdio.h>
main()
{int i;
struct contractinfor
{char num[9];
char name[8];
int chinese;
int english;
int mash;
int sum;
int score;
}studern[10];
for(i=0;i<10;i++)
{printf("\n please put the student number\n");
scanf("%s",studern[i].num);
printf("\n please put the student name\n");
scanf("%s",studern[i].name);
printf("\n please put the student chinese\n");
scanf("%d",studern[i].chinese);
printf("\n please put the student english\n");
scanf("%d",studern[i].english);
printf("\n please put the student mash \n");
scanf("%d",studern[i].mash);
studern[i].sum=studern[i].chinese+studern[i].english+studern[i].mash;
studern[i].score=studern[i].sum/3;
}
for(i=0;i<10;i++)
{printf( "please put the student number=%s",studern[i].num);
printf( "please put the student name=%s",studern[i].name);
printf( "please put the student sum=%d",studern[i].sum);
printf( "please put the student score=%d",studern[i].score);
}
}

取地址符呢?吃了?

另外,\n也吃了...


对你程序的改进

#include<stdio.h>

int main (void)
{
int i = 0;
struct contractinfor
{
char num[9];
char name[8];
int chinese;
int english;
int mash;
int sum;
int score;
}studern[3];//为了方便调试,这里就用一个小的数
while (i<3)//建议使用While循环
{
printf("\n-----\n Please put the %d student number:\n>", i+1);
scanf("%s",&studern[i].num);
printf(" Please put the student name:\n>");
scanf("%s",&studern[i].name);


printf(" Please put the student Chinese:\n>");
scanf("%d",&studern[i].chinese);

printf(" Please put the student English:\n>");
scanf("%d",&studern[i].english);

printf(" Please put the student Mash:\n>");
scanf("%d",&studern[i].mash);

studern[i].sum=studern[i].chinese+studern[i].english+studern[i].mash;
studern[i].score=studern[i].sum/3;
i++;
}
i = 0;
while (i<3)//输出
{
printf( "\n-----\nThe student number:\t%s\n",studern[i].num);//'\t'表示制表符
printf( "The student name:\t%s\n",studern[i].name);
printf( "The student sum:\t%d\n",studern[i].sum);
printf( "The student score:\t%d\n",studern[i].score);
i++;
}
return 0;
}

输出结果:

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-06-14
scanf要求变量地址,请在每个scanf中变量前面加上符号&,比如:
scanf("%s",&studern[i].num);
相似回答