我正在尝试分配一个短裤块,将其写入文件,然后将其读回。但是写入文件的数据与输出的数据不匹配。我已将问题隔离为以下代码。任何想法我做错了什么?
#define CHUNK_SIZE 1000
void xwriteStructuresToFile(FILE *file, void * structureData)
{
assert((fwrite(structureData, sizeof(short), CHUNK_SIZE, file)) == CHUNK_SIZE);
}
void wwbuildPtxFiles(void)
{
FILE *file = fopen("s:\\tv\\run32\\junky.bin", WRITE_BINARY);
int count = 10;
short *ptx = (short *) calloc(CHUNK_SIZE * count, sizeof(short ) );
memset(ptx, '3', sizeof(short) * CHUNK_SIZE * count);
for (int dayIndex = 0; dayIndex < count; ++dayIndex)
xwriteStructuresToFile(file, (void *) &ptx[ CHUNK_SIZE * sizeof(short) * dayIndex ]);
free(ptx);
fclose(file);
file = fopen("s:\\tv\\run32\\junky.bin", READ_BINARY);
int xcount = CHUNK_SIZE * count * sizeof(short );
for (int i = 0; i < xcount; ++i)
{
char x;
if ((x = getc(file)) != '3')
assert(false);
}
}