gpt4 book ai didi

c - fwrite() 会让你写一些超过文件大小的东西吗?

转载 作者:太空宇宙 更新时间:2023-11-04 07:58:17 26 4
gpt4 key购买 nike

FILE *f = fopen("file.txt", "ab+");
fseek(f, NUMBER_BIGGER_THAN_FILE_SIZE, SEEK_SET);
fwrite(&someStruct, sizeof someStruct, 1l, f);

因此,如果我有类似的东西,是否可以将其写入?如果没有,我该如何实现?

最佳答案

可以覆盖文件末尾。

但是在a模式(附加模式)下,fseekfwrite没有影响。

这在 C 标准 7.19.5.3 fopen 中有记录:

Opening a file with append mode ('a' as the first character in the mode argument) causes all subsequent writes to the file to be forced to the then current end-of-file, regardless of intervening calls to the fseek function.

来源:https://stackoverflow.com/a/5532426/2005038

关于c - fwrite() 会让你写一些超过文件大小的东西吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48473089/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com