TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: STEPHEN GAGE
from: MARKUS DREXELIUS
date: 1997-04-17 09:24:00
subject: Re: Random access files

Hi!
> 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 
'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.
For example: make use of the streams-capabilities of C++. (I'm using BC++  
4.52, I don't know, if it works with this syntax in visual c++):
---------cut off-------------------------------------
...
struct
{
   char* FromName[36];
   char* ToName[36];
   etc...
} msg;
fstream f;
f.open("file.hds", ios::in | ios::binary);
f.seekg( (sizeof(msg) * n - 1));
f.read((unsigned char*)&msg, sizeof(msg));
f.close();
...
---------------cut off-----------------------------------
with n is the number of the message between 1 and max.
I think, that the message-text hasn't a fixed size to store it in a  
structure. If so, you have to open the file like above and to read each  
message like in a sequentiel file until you reach your searched record...
If you've more questions: ask me! :-)
Bye, yours
Markus
--- CrossPoint v3.1
---------------
* Origin: (2:244/1661.4)

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™.