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 1 1948
Need Helps wrote: 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; }
You are reading binary data, not text. So you should open the file in
binary mode instead of text mode, by changing the fopen call to:
FILE *f = fopen(filename, "rb");
Character code 26 is an end-of-file marker in DOS text files. fread
notices this character and stops reading the file. (Before you fix the
fopen call, you should check the return value of fread, to confirm that
it is reading just one byte instead of four.)
--
David Olsen qg********@yahoo.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Lauren Quantrell |
last post by:
I have a stored procedure using Convert where the exact same Convert
string works in the SELECT portion of the procedure but fails in the
WHERE portion.
The entire SP is listed below....
|
by: Frank |
last post by:
For my website i would like to display the age of my son in years,
months, days and hours.
For now i manage to get a result for totals. Like the total number of
days.
This is the beginning:
...
|
by: Andy Dingley |
last post by:
I'm using this at present:
<p title="Publication date" ></p>
Works fine on screen, but Fangs/Jaws just reads it as "left bracket
twenty-eight slash zero slash two thousand five fifteen colon...
|
by: David |
last post by:
I'm new to DB2 and I need to write a query that will allow me to find
specific dates instead of me having a date range asked for, I want it to be
calculated.
I've done this in Access by coding...
|
by: Russell |
last post by:
I have an assignment that I have to complete. I have to write a
windows app in C#. Here is the spec:
1/ Date Comparison
Build a program that will find the number of days between two dates.
You...
|
by: Geoff Jones |
last post by:
Hi
I have a table that has a column with Date types.
I am trying to view certain rows in the table using a DataView.
Using the filter, I can view the rows with, for example, the date equal...
|
by: thebjorn |
last post by:
For the purpose of finding someone's age I was looking for a way to
find how the difference in years between two dates, so I could do
something like:
age = (date.today() - born).year
but that...
|
by: cygfocus |
last post by:
Hello Everyone,
I am rookie here, I am trying to create a shipment calendar.
Basically I would like to auto-populate records based upon monthly (12X) , weekly(X52) or Two Times a month...
|
by: Sebarry |
last post by:
Hi,
I'm trying to read the results of a database query into an XML document but it's only read so far and stopping. The XML document is as follows:
<?xml version="1.0" encoding="utf-8"?>
...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| | |