delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/02/00:52:31

Date: Sun, 1 Feb 1998 18:40:38 -0800 (PST)
Message-Id: <199802020240.SAA15924@adit.ap.net>
Mime-Version: 1.0
To: henri DOT ossi AT mail DOT htk DOT fi, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Fopen, fgetc, pac_getc etc. problem

At 04:40  1/28/1998 +0200, Henri Ossi wrote:
>So, could someone tell me, how?
`*getc' reads *bytes*. So you can just use it. If it doesn't work, you have
some other problem. (Check that you opened the file in binary mode!)

There is also this solution, which you shouldn't need to use:

char c;
fread(&c, sizeof(char), 1, f);

>
>Henri Ossi wrote:
>
>> Hi.
>> I've made a fractal program, and It can produce 24bit images on the
>> screen (cool :)
>> Now I'm planning to make it save the image to a .TGA file.
>>
>> I downloaded the TGA file specification, but I have one problem.
>> How can I
>>
>> 1)read a byte from a file
>> 2)write byte to a file
>>
>> Char is a word(16bit), right?
>> So, fgetch reads a word. But I have to be able to read & write
>> a byte.
>>
>> How is this done?
>>
>> I looked from the source code of allegro, and there the TGA file
>> reader
>> was using "pack_getc()" -function
>> to get bytes from the packet file, but I coudln't find the code of the
>>
>> function.
It is there (see `src/file.c', I think). It acts the same as `getc' except
when reading from a compressed (packed) file, in which case it decompresses.
>>
>> I've been thinking about this kind of solution, could it work?
>>
>> c = "read the word from the file";
Note that the obvious way to "read a word" seems to be `getw', but that
reads a 32-bit long.
>> byte1 = c >> 8;
>> byte2 = (c <<8)>>8;
>>
>> But I still can't write bytes with that one...
Well...
c = byte2;
c |= byte1 << 8;

But ignore all this :), `getc' should work.

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019