From: | Allan Odgaard |
Date: | 18 Aug 2001 at 17:40:51 |
Subject: | [amiga-c] Re: Peek$ing |
Hello Twelvebullets,
> If I had the following
> mem = AllocMem(2000, MEMF_CLEAR | MEMF_PUBLIC);
> lock = Open("Ram:test", MODE_OLDFILE);
> size = Read(lock, mem, 2000);
> How do I read 15 bytes from mem+20 into Char * string. ??
TEXT str[15];
CopyMem(((UBYTE *)mem)+20, str, 15);
However you probably want to look into structures. E.g.:
struct MyFileContents
{
ULONG SomeFlag;
...
TEXT MyString[15];
...
};
And then simply do:
struct MyFileContents file;
Read(lock, &file, sizeof(file));
printf("%s\n", file.MyString);
This of course will only work gracefully on a big endian machine which
doesn't rearrange or pad structure declarations (which is true on the
Amiga).
You may also instead do partial reads a la:
UBYTE first[20];
Read(lock, first, sizeof(first));
TEXT string[15];
Read(lock, string, sizeof(string));
...
With many small reads you may want to use buffered i/o to speed
things up (FGetC()/FGetS()).
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Secure all your Web servers now: Get your FREE Guide and learn to: DEPLOY THE LATEST ENCRYPTION,
DELIVER TRANSPARENT PROTECTION, and More!
http://us.click.yahoo.com/VihfLB/nT7CAA/yigFAA/dpFolB/TM
---------------------------------------------------------------------~->
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/