Klempie wrote: unsigned int dict_size = readintbigendian(in);
in your code for writting you didn't shown writting dictionary size.
Klempie wrote: if(!writeintbigendian ( out, dictionary[i+1] ))
write start from 1;
may be you are writting it, I still don't believe problem in file read if you properly used it, if you not writting the dictionary size and read it, the fgetc(file); return EOF at end of file at that time, EOF value is -1 you get it instead of -230; you are not checking error status of fgetc, check it.
the following code for me works well,
#include <stdio.h>
FILE *fpWrite = NULL, *fpRead = NULL;
int iArrDataWrite[] = { 1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42<big>,-230</big>,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60
};
#define DATA_SIZE (sizeof(iArrDataWrite)/sizeof (iArrDataWrite[0]))
int iArrDataRead[DATA_SIZE] = {0};
int main( void )
{
int numclosed;
if((fpWrite = fopen( "bigEndianData.bin", "wb" )) == NULL )
{
printf( "The file 'bigEndianData.bin' was not opened for writting\n" );
return 0;
}
else
{
printf( "The file 'bigEndianData.bin' was opened for writting\n" );
printf( "Writting to file\n" );
for (int i = 0; i < DATA_SIZE; i++)
{
printf( "%d,", iArrDataWrite[i]);
if (((i + 1) % 10) == 0) printf( "\n");
writeintbigendian(fpWrite, iArrDataWrite[i]);
}
fclose( fpWrite);
fpWrite = NULL;
}
if((fpRead = fopen( "bigEndianData.bin", "rb" )) == NULL )
{
printf( "The file 'bigEndianData.bin' was not opened for reading\n" );
return 0;
}
else
{
printf( "The file 'bigEndianData.bin' was opened for reading\n" );
printf( "reading from file\n" );
for (int i = 0; i < DATA_SIZE; i++)
{
iArrDataRead[i] = readintbigendian(fpRead);
printf( "%d,", iArrDataRead[i]);
if (((i + 1) % 10) == 0) printf( "\n");
}
fclose( fpRead);
fpRead = NULL;
}
return 0;
}
modified on Friday, May 9, 2008 10:13 AM
|