G
Guest
Hello. I'm writing an application that writes to a file a month, day, year, number of comments, then some strings for the comments. So the format for each record would look like:
mdyn"comment~""comment~"\n
Now, I wrote some code to read these records, and it works perfectly for every date I've tried it on, except when the day is 26. I tried saving a record for 6/26/2004 and 7/26/2004 and it read it in as the day, year, and number of comments all being 0, with the month being correct. Does anyone have any clue whatsoever as to what the problem might be? Why would the number 26 be special? I tested it and know that it is writing it to the file correctly, so the problem is in the reading. Here is some sample reading code that produces the problem:
DWORD MyOpenFile()
{
DWORD br, m, d, yr, n;
DWORD nBuffer[200];
char ch = ' ';
File * f = fopen(filename, "r");
if (f == NULL)
return 0;
//mdyn"comment~""comment~"\n
br = fread(nBuffer, sizeof(DWORD), 4, f);
m = nBuffer[0]; //so far always correct
d = nBuffer[1]; //if date was the 26th of the month, == 0
yr = nBuffer[2]; //if date was the 26th of the month, == 0
n = nBuffer[3]; //if date was the 26th of the month, == 0
fclose(f);
return 0;
}
Any help would be greatly appreciated, as I am completely dumbfounded. Thanks in advance!
-NH
mdyn"comment~""comment~"\n
Now, I wrote some code to read these records, and it works perfectly for every date I've tried it on, except when the day is 26. I tried saving a record for 6/26/2004 and 7/26/2004 and it read it in as the day, year, and number of comments all being 0, with the month being correct. Does anyone have any clue whatsoever as to what the problem might be? Why would the number 26 be special? I tested it and know that it is writing it to the file correctly, so the problem is in the reading. Here is some sample reading code that produces the problem:
DWORD MyOpenFile()
{
DWORD br, m, d, yr, n;
DWORD nBuffer[200];
char ch = ' ';
File * f = fopen(filename, "r");
if (f == NULL)
return 0;
//mdyn"comment~""comment~"\n
br = fread(nBuffer, sizeof(DWORD), 4, f);
m = nBuffer[0]; //so far always correct
d = nBuffer[1]; //if date was the 26th of the month, == 0
yr = nBuffer[2]; //if date was the 26th of the month, == 0
n = nBuffer[3]; //if date was the 26th of the month, == 0
fclose(f);
return 0;
}
Any help would be greatly appreciated, as I am completely dumbfounded. Thanks in advance!
-NH