结构数组问题 麻烦大神帮看一下
#include<stdio.h>struct student
{
char name[20];
char num[20];
char sex;
char password[20];
float math_score;
float china_score;
float c_score;
};
int main()
{
int i;
struct student *s=NULL;
FILE *fp;
fp=fopen("stu_info.txt","w");
if(NULL == fp)
{
printf("open error\n");
}
for(i=0; i<5;i++)
{
printf("name:\n");
scanf("%s",s[i].name);
printf("num:\n");
scanf("%s",s[i].num);
getchar();
printf("sex:\n");
scanf("%c",&s[i].sex);
printf("password:\n");
scanf("%s",s[i].password);
printf("math_score:\n");
scanf("%f",&s[i].math_score);
printf("china_score:\n");
scanf("%f",&s[i].china_score);
printf("c_score:\n");
scanf("%f",&s[i].c_score);
fprintf(fp,"%s%s%c%s%f%f%f\n",s[i].name,s[i].num,s[i].sex,s[i].password,s[i].math_score,s[i].china_score,s[i].c_score);
}
fclose(fp);
return ;
}
编译正常能过 然后会出现如下问题name:
xiaoming
num:
段错误 (核心已转储)