好友
阅读权限10
听众
最后登录1970-1-1
|
error C2018: unknown character '0xa3' ---> C语言中报这个错误是代码里有中文字符
/******
在此程序中,通过定义学生结构体变量,存储了学生的学号、姓名和三门课的成绩。
所有的学生的数据均以二进制方式输出到文件中。函数fun的功能是重写形参filename所指文件中最后一个学生的数据,
即用新的学生数据覆盖该学生原来的数据,其他学生的数据不变。
******/
#include<stdio.h>
#define N 5
typedef struct student{
long sno;
char name[10];
float score[3];
}STU;
void fun(char *filename,STU n)
{
FILE *fp;
fp =fopen(filename,"rb++");
fseek(fp,-(long)sizeof(STU),SEEK_END);
fwrite(&n,sizeof(STU),1,fp);
fclose(fp);
}
main()
{
STU t[N] = {{10001,"马超",91,92,77},{10002,"刘备",75,60,88},{10003,"张飞",60,60,60},{10004,"关羽",70,80,90},{10005,"貂蝉",78,87,69}};
STU n={1006,"吕布",100,99,99},ss[N];
int i,j;FILE *fp;
fp =fopen("student.dat","wb");
fwrite(t,sizeof(STU),N,fp);
fclose(fp);
fp =fopen("student.dat","rb");
fread(ss,sizeof(STU),N,fp);
fclose(fp);
printf("\n The original data :\n\n");
for(j =0;j<N;j++)
{
printf("\n No:%ld Name :%-8s Scores:",ss[j].sno,ss[j].name);
for(i =0;i<3;i++)
{
printf("%6.2f",ss[j].score);
printf("\n");
}
}
fun("student.dat",n);
printf(" \n The data after modifying :\n\n");
fp =fopen("student.dat","rb");
fread(ss,sizeof(STU),N,fp);
fclose(fp);
for(j =0;j<N;j++)
{
printf("\n No:%ld Name :%-8s Scores:",ss[j].sno,ss[j].name);
for(i =0;i<3;i++)
{
printf("%6.2f",ss[j].score);
printf("\n");
}
}
}
|
免费评分
-
查看全部评分
|