Mail Archives: djgpp/1999/02/19/20:05:45
From: | "James Kermode" <james DOT kermode AT usa DOT net>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: HELP: File-I/O under DJGPP ???
|
Date: | Sat, 20 Feb 1999 01:03:35 -0000
|
Organization: | Customer of Planet Online
|
Lines: | 54
|
Message-ID: | <7al1kq$cl8$1@news5.svr.pol.co.uk>
|
References: | <01be5c52$32c81680$96ab9bc1 AT default>
|
NNTP-Posting-Host: | modem-28.yttrium.dialup.pol.co.uk
|
X-Trace: | news5.svr.pol.co.uk 919472602 12968 62.136.19.28 (20 Feb 1999 01:03:22 GMT)
|
NNTP-Posting-Date: | 20 Feb 1999 01:03:22 GMT
|
X-Complaints-To: | abuse AT theplanet DOT net
|
X-Newsreader: | Microsoft Outlook Express 4.72.3110.1
|
X-MimeOLE: | Produced By Microsoft MimeOLE V4.72.3110.3
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Hi,
If you use fopen() to open the file, rather than open() and save the result
in a FILE*, then you can move through the file using fseek()
eg:
char some_char;
FILE *fp;
fp = fopen("myfile.pcx","rb");
if (fp == NULL)
{
cout << "error";
return 0;
}
fseek(fp,128,SEEK_SET); // go 128 bytes into file (ie skip the header)
....
some_char = fgetc(f);
....
fseek(fp,-768,SEEK_END); // skip back 768 bytes from the END of the file
I have written a PCX class if you are interested...
Hope this helps,
James Kermode
>I am writing a little class for loading .pcx-files and showing them on the
>screen.
>My problem is that I use the following code to open a .pcx-file and read it
>as follows:
>
>int handle;
>handle=open(name);
>if (handle<0) { cout<<"ERROR!"; exit(1); }
>
>Clear so far? I hope so, as this was just the opening of the file.
>
>I read it like this:
>
>int variable;
>read(handle, variable, sizeof(int));
>
>OK?
>
>My Problem now is that I need to change my position in the file (normally I
>use fseek or such a kind but here it doesn't work).
>What can I do to change my position?
>
>I really NEED help fast!
>
>Fozzie
>
- Raw text -