/*
* 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;
}
这两个函数能够用来读写二进制数据。