二级C语言题1_1
error C2018: unknown character '0xa3' ---> C语言中报这个错误是代码里有中文字符/******
在此程序中,通过定义学生结构体变量,存储了学生的学号、姓名和三门课的成绩。
所有的学生的数据均以二进制方式输出到文件中。函数fun的功能是重写形参filename所指文件中最后一个学生的数据,
即用新的学生数据覆盖该学生原来的数据,其他学生的数据不变。
******/
#include<stdio.h>
#define N 5
typedef struct student{
long sno;
char name;
float score;
}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 = {{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;
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.sno,ss.name);
for(i =0;i<3;i++)
{
printf("%6.2f",ss.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.sno,ss.name);
for(i =0;i<3;i++)
{
printf("%6.2f",ss.score);
printf("\n");
}
}
}
https://c.runoob.com/compile/11/
运行无异常;
主函数没写返回类型。
int main
----运行结果----
The original data :
No:10001 Name :马超 Scores:0.00
0.00
0.00
No:10002 Name :刘备 Scores:0.00
0.00
0.00
No:10003 Name :张飞 Scores:0.00
0.00
0.00
No:10004 Name :关羽 Scores:0.00
0.00
0.00
No:10005 Name :貂蝉 Scores:0.00
0.00
0.00
The data after modifying :
No:10001 Name :马超 Scores:0.00
0.00
0.00
No:10002 Name :刘备 Scores:0.00
0.00
0.00
No:10003 Name :张飞 Scores:0.00
0.00
0.00
No:10004 Name :关羽 Scores:0.00
0.00
0.00
No:1006 Name :吕布 Scores:0.00
0.00
0.00
页:
[1]