Connecting Tech Pros Worldwide Help | Site Map

working code stops working

Newbie
 
Join Date: Jul 2009
Posts: 4
#1: Aug 13 '09
This has been quite frustrating. At the end of my program, I checksum the file I'm working on. Yesterday, the code worked. I made a few unrelated changes and now the code just doesn't even do what it is supposed to.

newFile is an fstream object opened under binary.

##############################################

newFile.seekp(0, ios::end); //without this it
newFile.put(0); // won't write

// checksum
newFile.seekg(55, ios::beg);
unsigned short nCheckSum = 0;
unsigned char chCurrentCheck;
for (int iii = 0; iii < nThisFileSize + 19; iii++)
{
newFile.read((char*)(&chCurrentCheck), 1);
nCheckSum += chCurrentCheck;
cout << chCurrentCheck;
}
newFile.seekp(-1, ios::end); //actually supposed to be 0
newFile.write((char*)(&nCheckSum), 2);
cout << nCheckSum << endl;

##################################################

This code used to work, but stopped for no reason. And if I put the write before the checksum, it works. Also I believe the checksum is wrong, that's what the trouble is.

Any ideas?
Reply