in this code i check if i'm getting data blocks in order, if not inorder i return NULL,i.e ask for next block, if in order i write the contents of data block to a file pointed by fpdddb.
the contents of DDB_Parser.BlockDataByte array keep changing every time.
what is the reason fwrite writes garbage values to the file.
DDB_Parser.BlockDataByte is of unsigned char type.
thanks in advance, if anyone looks into this code snippet.

for(;bcount<NoOfBlocks;bcount++)
{
 printf("-----------------------------------------\n");
 printf("DDB Module Id %x\n",DDB_Parser.ModuleId);
 printf(" Data Block Number %d\n",DDB_Parser.BlockNumber);
                     
					
  if(bcount!= DDB_Parser.BlockNumber)
 {
 return NULL;
 }
else
{
       fwrite(DDB_Parser.BlockDataByte,blocksize,1,fpddb);
                          fflush(stdin);
}

The first thing you should do is initialize BlockDataType array with all 0s before doing anything else with it -- that will clear the array of all random data. Now lin line 14 fwrite() will write 0s for all unused bytes in that array. fwrite() will write blocksize number of bytes to the file, regardless of what BlockDataByte contains. Note that the contents of binary files can not be read by text editors such as Notepad.

This question has already been answered. Start a new discussion instead.