C语言: 无法实现想要的功能
#include<stdio.h>#include<string.h>
#define A "please input"
struct student
{
char name[15];
int math;
int chinese;
int english;
};
int main()
{
struct student stu[10];
int i,n;
char a[100],filename[100];
FILE *fp;
printf(A" filename:\n");
scanf("%s",filename);
printf("please input number of students:\n");
scanf("%d",&n);
printf("please input information:\n");
for(i=0;i<n;i++)
{
printf(A" name:\n");
scanf("%s",stu[i].name);
printf(A" math:\n");
scanf("%d",&stu[i].math);
printf(A" chinese:\n");
scanf("%d",&stu[i].math);
printf(A" english:\n");
scanf("%d",&stu[i].english);
}
if((fp=fopen(filename,"wb"))==NULL)
printf("error!!");
for(i=0;i<n;i++)
fwrite(&stu[i],sizeof(struct student),1,fp);
fclose(fp);
return 0;
}
能在知道路径建立文件但是文件内容是乱码
追问:那应该怎么改呢。用fprintf的话name这一块无法输入