: : : : : : : : Hi,
: : : : : : : :
: : : : : : : : I have written a routine for checksum calculation (XOR). In this I will be reading a binary file. But when I try to read a binary file , i see that only special characters get printed at the output. How do I proceed with it. Please Help me in resolving the issue...
: : : : : : : :
: : : : : : : : Do suggest me if there are any kind of Examples available for checksum calculation.
: : : : : : : :
: : : : : : : : Best Regards,
: : : : : : : : XYZ
: : : : : : : :
: : : : : : : What do you want to print? The bytes in the file?
: : : : : : :
: : : : : : : Steph
: : : : : : :
: : : : : : Hi Steph,
: : : : : :
: : : : : : Thank you very much for the quick response. Yes I want to print the bytes in a file, & also XOR each byte & print the final checksum value.
: : : : : : But i can only find special characters getting printed & some junk checksum values.
: : : : : :
: : : : : :
: : : : : :
: : : : :
: : : : :
: : : : : It seems like the bug is in the display routine and not in the checksum.
: : : : : Please post the code.
: : : : :
: : : :
: : : :
: : : : Hi Steph... here is the code....
: : : :
: : : :
: : : :
: : : : #include <stdio.h>
: : : :
: : : : #include <stdlib.h>
: : : :
: : : : int main(void)
: : : :
: : : : {
: : : :
: : : : FILE *fp;
: : : :
: : : : char buf[6];
: : : :
: : : : /* Open an existing binary file for reading. */
: : : :
: : : : if (( fp = fopen ( "C:\\iCube3.3.iic", "rb" ) ) == NULL )
: : : :
: : : : {
: : : :
: : : : printf ( "Cannot open file\n" );
: : : :
: : : : exit ( 1 );
: : : :
: : : : }
: : : :
: : : : /* Read characters from the file to the buffer. */
: : : :
: : : :
: : : :
: : : : fread ( buf, 1, sizeof(buf), fp );
: : : :
: : : : printf ( "%s\n", buf );
: : : :
: : : :
: : : :
: : : : fclose ( fp );
: : : :
: : : : return 0;
: : : :
: : : : }
: : : :
: : :
: : :
: : : Yep, as I suspected you are using the wrong print algo. You can't print binary data as text, it won't make sense.
: : :
: : : To view binary data as hex, you need to do like this:
: : :
: : :
: : : int i;
: : :
: : : ...
: : : for(i=0; i<sizeof(buf); i++)
: : : {
: : : if(buf[i] < 0x10)
: : : printf("0%X ", (unsigned char)buf[i]);
: : : else
: : : printf("%X ", (unsigned char)buf[i]);
: : : }
: : :
: : :
: :
: :
: : Hi Steph,
: :
: : Thank you. Now m able to read the file... i will proceed with the checksum part & post a que if i have any issues.....
: :
: : Thanks once again.........
: :
: I would just like to add that this is Lundin who gave you the solution.

I only posted the first message asking you for more information. After that I had a four hour class so I wasn't able to read your answer. But Lundin was. So you should thank Lundin, not me.
:
: Steph
:
Thank U Lundin....