Path: utzoo!attcan!uunet!lll-winken!lll-lcc!pyramid!leadsv!ereed From: ereed@leadsv.UUCP (Ed Reed) Newsgroups: comp.sys.mac.programmer Subject: Checksum does not add up Message-ID: <3567@leadsv.UUCP> Date: 25 Jul 88 21:55:24 GMT Distribution: na Organization: LMSC-LEADS, Sunnyvale, Ca. Lines: 60 I am having a problem with a program I am writing on a Macintosh II. The program is being written in Lightspeed C ver. 3.0, and what follows is the applicable code: main() { .....other declarations char DataIn[256]; long HeaderIn; short CheckSumIn; short CheckSum; char *DataInPtr; long *HeaderInPtr; short *CheckSumPtr; .....other initializations DataInPtr = &DataIn[0]; HeaderInPtr = &HeaderIn; CheckSumPtr = &CheckSumIn; .....other statements to open the serial driver(port a) to reset the serial port to 19.2 Kb to get hard disk information to create a data file to open a data file while (!(Button()) { CheckSum = 0; FSRead( -6, &HeaderCount, &HeaderInPtr ); FSRead( -6, &DataCount, &DataInPtr ); FSRead( -6, &SumCount, &CheckSumPtr ); for (i = 0; i < 256; i++) { CheckSum += (short) DataIn[i]; } if (CheckSum != CheckSumIn) { .....write buffer to file exit program } } } The problem is that when I do the for loop the CheckSum total does not add up right. I added a print statement inside the loop in order to make sure what was being added was correct. I was annoyed to find out it wasn't. Instead of 0 - 255, which was being sent, I was getting 9-39 hex, 50-ff hex, 0-a hex, and then odd junk. But the interesting thing was when I did a hex dump of the file it was correct. Now does anyone out there know why I can't do a checksum. Does the Mac o.s. cause this problem or am I getting the structure of the read command wrong? I read "Inside Mac, vol 2" which describes the I/O calls and I think I'm right, so what is wrong? Please respond directly, do not post your reply. Joe Hughes pyramid!leadsv!jhughes