TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: STEPHEN GAGE
from: KEVIN CAMPBELL
date: 1997-04-14 16:19:00
subject: Random access files

 > Hi! I'm trying to write a program that will read a hudson message base,
 > and convert any new messages to  files, which can then be read in
 > Internet Explorer or similar.
 > I've hit a brick wall straight away; I can't read from the hudson
 > message base! Well, tell a lie, I have managed to get some code to work
 > in Visual Basic, but that is so slow that it is unusable (it takes
 > around 1 hour to toss 50 messages, on a 686/150+).
Well chuck VB then if it's soo slow. VB shouldn't be that bad though. Check
you've not got any Big time-consuming pieces in your code. Also, check that 
you
are choosing the right compile option, there's more than one if I can 
remember.
Don't choose the debug one if you want to test for speed.
 > I've got a spec of how the Hudson message base is stored, but I can't
 > read the files from the disk! I have a spec similar to the following:
 > char* FromName[36];
 > char* ToName[36];
 > char* Subject[72];
 > int origzone;
 > int destzone;
 > etc...
 > How do I read the n'th chunk from the disk? I'm learning c++ at Uni, but
 > I'm only a first year, and we've only used the file streams so far... I
 > think I will probably need to use structs as well, but I have no
 > experience whatsoever of using these beasts.
As for structs, they are simple groupings of variables in a single object:
struct hudsonmsg{
  char FromName[36];
  char ToName[36];
  char Subject[72];
  ...etc...
};
note - you are defining FromName as an array of character pointers... this is
wrong.
structs are very useful for random access files. Create a new of object of 
type
'hudsonmsg', eg:
struct hudsonmsg message;
Now use fread to read a hudson message into the structure:
fread(&message,sizeof(message),1,file);
where file is the hudson message base that you've already opened with 
open().
Note - check this, as I may have made a typo somewhere.
To achieve random-access, simply move the current file position back and 
forth.
If you've any further Q's, just ask :)
- Kev
--- FMail/386 1.02
---------------
* Origin: Mail shipped from Deimos Spaceport (2:259/17)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.