C语言编程问题(请高手指教,这个程序能否运行成功,若不行请修正,谢)

来源:百度知道 编辑:UC知道 时间:2024/06/01 13:32:40
#include<stdio.h>
#include<string.h>
struct student
{ char num[10];
char name[8];
int score_ENG,score_CHN,score_math;
double avr;
double avr_ENG;
double avr_CHN;
double avr_math;
}stu[30],stu1[30];
void main()
{ int i,j,t,t1,t2,sum,sum_ENG,sum_CHN,sum_math;
char *temp,*temp1;
double avr_ENG,avr_CHN,avr_math;
FILE *fp;
j=0;
sum_ENG=0;
sum_CHN=0;
sum_math=0;
for(i=1;i<=30;i++)
{ printf("\n please input NO. %d score:\n",i);
printf("stuNO:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
printf("score_ENG.");
scanf("%d",&stu[i].score_ENG);
printf("score_CHN.");
scanf("%d",&stu[i].score_CHN);
printf("score_math.");
scanf("%d",&stu[i].score_math);

temp和temp1两个指针没初始化吧.你定义了两个char*型的指针,没有分配空间给它们,后面直接用strcpy(temp,stu[i].num)和strcpy(temp1,stu[i].name)肯定要出错的.
所以可以这样修改:
char *temp = new char[8],*temp1 = new char[8]; //line 14