c - 在c中将ByteArray写入文件

标签 c pointers arrays fwrite

我有一个包含一些 ByteArray 数据的结构

typedef struct {
    uint32_t length;
    uint8_t* bytes;
} FREByteArray;  

在这里我试图将其保存到文件中

FREByteArray byteArray;

if((fileToWrite = fopen(filePath, "wb+")) != NULL){
    fwrite(&byteArray.bytes, 1, byteArray.length, fileToWrite);
    fclose(fileToWrite);
}

但这似乎并没有保存所有数据,保存的文件大小为16KB,实际数据约为32KB。我认为 fwrite 无法将整个字节数组写入文件。

这是保存 ByteArray 的正确方法吗? fwrite 在一次调用中可以处理的数据量是否有限制?

最佳答案

替换

fwrite(&byteArray.bytes, 1, byteArray.length, fileToWrite);

fwrite(byteArray.bytes, 1, byteArray.length, fileToWrite);

正如 @Sourav Ghosh 所指出的,请确保 byteArray.bytes 指向正确的源位置。

关于c - 在c中将ByteArray写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28405884/

相关文章:

php - 使用 PHP 从 mySQL 表返回列名

java - 将数组传递给注释的语法

c++ - opencv中的轮廓选择

c - ansi-c 将 char 转换为 ascii 表示的 int

Bison 目标的 CMake 自定义命令

c - 按 qsort 排序后缀

C:令人惊讶的数组结果

c++ - 使用 dynamic_cast : what happenes to the allocated memory 强制转换后删除指针

使用 ctypes 在 C 中动态访问 Python 变量

c - 最大和连续子数组使用递归直接输出结果