求助:为何程序运行到print函数就停止工作?
程序代码:
#include<stdio.h> #include<string.h> #include<stdlib.h> #define NULL 0 #define length sizeof(struct student) struct score { float Chinese,Math,English; }; struct student { char Name[20]; int Num; struct score Score; float Allscore; char Sex; }stu[300],yuanshi[300],change; int n=0; void input(); void print(); void input() { int i; for(i=n;;i++) { printf("请输入第%d位学生姓名,输入end停止输入\n",n+1); scanf("%s",&stu[i].Name); if(strcmp(stu[i].Name,"end")==0) { break; } printf("请输入该学生学号\n"); scanf("%d",&stu[i].Num); getchar(); printf("请输入该学生性别,男.m,女.w\n"); scanf("%c",&stu[i].Sex); getchar(); printf("请输入该学生语文,数学,英语考试成绩,用空格分开\n"); scanf("%f%f%f",&stu[i].Score.Chinese,&stu[i].Score.Math,&stu[i].Score.English); stu[i].Allscore=stu[i].Score.Chinese+stu[i].Score.Math+stu[i].Score.English; n=n+1; } } void print() { printf("Name Sex Num Chinese Math English Allscore\n"); for(int i=0;i<n;i++) { printf("%-15s%-5s%-5d%-5f%-5f%-5f%-5f\n",stu[i].Name,stu[i].Sex,stu[i].Num,stu[i].Score.Chinese,stu[i].Score.Math,stu[i].Score.English,stu[i].Allscore); } } void main() { input(); print(); }