Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2004

Tip: Looking for answers? Try searching our database.

file io, reading in dates, problems with the 26th of every month..

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Need Helps - 18 Jun 2004 22:38 GMT
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
David Olsen - 18 Jun 2004 23:36 GMT
> 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
[quoted text clipped - 24 lines]
> 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.)

Signature

David Olsen
qg4h9ykc5m@yahoo.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.