C 编程 fwrite 跳转到文件末尾
C programming fwrite jumps to end of file
我正在编写一个C模块,遇到了一个我以前从未见过的有趣问题。
// Many other operations before this point
fseek(samples_file, 0, SEEK_SET);
printf("ftell A1 %llun", ftell(samples_file));
count = fwrite(channel_buffer+chan_type.size*set_index, 1, chan_type.size, samples_file);
printf("count %llun", count);
printf("ftell A2 %llun", ftell(samples_file));
// Many more operations to come after this point
当我运行模块时,我得到如下所示的打印输出:
ftell A1 0
count 8
ftell A2 6018
我已将文件指针设置为文件的开头。当我写入一些数据时,它应该将数据写出我想要的位置,然后随着写入的字节数(在本例中为 8)递增文件位置。但是,当我做一个ftell时,似乎位置突然跳到了6018(恰好是文件的原始大小加8)。
为什么会发生这种情况,如何防止此行为?
听起来文件已在追加模式下打开。检查第二个参数中没有"a"
fopen()
。
相关文章:
- C++编程从外部文本文件定义数组大小
- C++模板编程设计问题 - 根据输入文件返回不同的类型
- 以编程方式防止重命名或删除文件,但仍使其可写
- 在c++编程中的文件夹中创建文件
- 在C++模块化编程中,如何组装.cpp和.h文件
- 如何将 Cython 生成的模块从 python 导入到 C/C++ 主文件?(C/C++编程)
- Windows可以编程更改防火墙配置文件
- 音频编程 SDL - 如何使用 wav 文件在命令行中指定频率切割
- 是否可以以编程方式创建迷你转储文件而不会崩溃?
- 如何以编程方式查找从 html 引用的所有文件
- 如何以编程方式设置应用程序EXE文件的图标
- 如何在C / C++中以编程方式查找"Saved Games"文件夹?
- 如何以编程方式知道Adobe Reader完成了加载文件
- 通过编程C MFC查找目录中的文件列表
- 'Good'通过条目维护/更新/访问文件的编程形式
- 以编程方式馈送 KML 文件并检索/生成.png文件
- C 编程 fwrite 跳转到文件末尾
- 在Mac OS X中仅使用给定的文件路径以编程方式装载磁盘/卷
- 套接字编程:"接受:错误的文件描述符"
- C++中的多文件编程实践