Mail Archives: djgpp/1998/08/04/13:57:54
Xee'Gh wrote:
>
> Hi, I just started to make new program with graphics.I know that i should
> use allegro but i just have this kind of fever to make this working. I
> wrote a code that would
> unpack pcx files, but i only get on freaky error.
>
> p.c:77 warning: comparison is always 0 due to limited data type.
>
> i cut& paste the code what the error message refers to. Please HELP me.
> And if you know that this code has faults please tell me how would you do
> it.
> or if theres just some minor faults please tell me how to fix them.
>
> thanks in advance.
>
> write to pekkaka AT dlc DOT fi with possible fixes.
>
> ''Code'''
>
> int UnpackPCX(FILE *fh, char *buffer, int width, int Height)
> {
> char palette[768];
> char *wbuf, *wptr, c, l;
[snipped]
> if (c > 191) /* This is the error point */ <77>
> {
[snipped more]
You declare `c' as `char'. Here, a `char' is an 8-bit value, signed by
default. Thus, its range is from -128 to 127. Clearly, if `c' can
never exceed 127, it will never be greater than 191.
You probably want to declare `c' as `int'; that is standard procedure
for character variables. It has the added advantage that you will be
able to correctly handle the EOF value, which is outside the range of
even an `unsigned char'.
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -