关于文件操作中文件标记的问题int main(){\x05FILE *fp;\x05int num,ps;\x05float score;\x05fopen_s(&fp,"stu.txt","w+");\x05scanf_s("%d%f",&num,&score);\x05while (num = 0)\x05{\x05\x05fprintf(fp,"%d,%f\n",num,score);\x05\x05ps = ftell(fp);\x
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/30 01:06:22
关于文件操作中文件标记的问题int main(){\x05FILE *fp;\x05int num,ps;\x05float score;\x05fopen_s(&fp,"stu.txt","w+");\x05scanf_s("%d%f",&num,&score);\x05while (num = 0)\x05{\x05\x05fprintf(fp,"%d,%f\n",num,score);\x05\x05ps = ftell(fp);\x
关于文件操作中文件标记的问题
int main()
{
\x05FILE *fp;
\x05int num,ps;
\x05float score;
\x05fopen_s(&fp,"stu.txt","w+");
\x05scanf_s("%d%f",&num,&score);
\x05while (num = 0)
\x05{
\x05\x05fprintf(fp,"%d,%f\n",num,score);
\x05\x05ps = ftell(fp);
\x05\x05printf("ps=%d",ps);
\x05\x05scanf_s("%d%f",&num,&score);
\x05}
\x05rewind(fp);
\x05while feof(fp))
\x05{
\x05\x05fscanf_s(fp,"%d,%f",&num,&score);
\x05\x05printf("num=%d,score=%f\n",num,score);
\x05}
\x05fclose(fp);
}
为什么输入后ps=13,与设想的数据字节数不同啊?
float是4个字节吧,应该是8个字节一共.我的老师说可能与内存对齐有关,但是具体是什么样子的呢?
关于文件操作中文件标记的问题int main(){\x05FILE *fp;\x05int num,ps;\x05float score;\x05fopen_s(&fp,"stu.txt","w+");\x05scanf_s("%d%f",&num,&score);\x05while (num = 0)\x05{\x05\x05fprintf(fp,"%d,%f\n",num,score);\x05\x05ps = ftell(fp);\x
整型4字节
float8字节
写完之后,就到了13字节,你觉得应该是几字节?