二进制文件读写函数

来源:互联网 发布:c语言预编译指令 编辑:程序博客网 时间:2024/06/05 08:45


/* * dstBuf      : Storage location for data. * size        : Item size in bytes. * startEle    : Which is the start element to read. (counts from 0) * count       : Maximum number of items to be read. * fileName    : Name of the file to be read. */int abanFRead(void *dstBuf, size_t size, long startEle, size_t count, char *fileName){  FILE *file = fopen(fileName, "rb");  fseek(file, startEle*size, SEEK_SET);  fread(dstBuf, size, count, file);  fclose(file);  return 0;}/* * srcBuf      : Pointer to data to be written. * size        : Item size in bytes. * startEle    : Which is the start element position to be written. (starts from 0) * count       : Maximum number of items to be written. * fileName    : Name of the file to be read. */int abanFWrite(const void *srcBuf, size_t size, long startEle, size_t count, char *fileName){  FILE *file = fopen(fileName, "wb");  fseek(file, startEle*size, SEEK_SET);  fwrite(srcBuf, size, count, file);  fclose(file);  return 0;}

这两个函数能够用来读写二进制数据。

0 0