home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!mcsun!sunic!ugle.unit.no!sigyn.idt.unit.no!bjornmu
- From: bjornmu@idt.unit.no (Bj|rn P. Munch)
- Subject: Re: Curious bug...
- Message-ID: <1992Jul23.114202.1684@ugle.unit.no>
- Sender: news@ugle.unit.no (NetNews Administrator)
- Organization: Div. of CS & Telematics, Norwegian Institute of Technology
- References: <1992Jul22.050021.3974@uwm.edu>
- Date: Thu, 23 Jul 92 11:42:02 GMT
- Lines: 43
-
- In article <1992Jul22.050021.3974@uwm.edu>, pegasus@csd4.csd.uwm.edu (David R Hucke) writes:
- |> Hello everybody!
- |>
- |> I have a program that I have written in Quick C 2.5 that doesn't work right and
- |> I am stumped.
-
- [...]
-
- |> #include <stdio.h>
- |>
- |> main()
- |> {
- |>
- |> short far *SCREEN = (short far *) 0xB8000000;
- |> short menu[8][20];
- |> short x,y;
-
- [...]
-
- |> fscanf(file,"%c%c",&x,&y); /* reading in attribute and
- |> character bytes */
-
- You have a problem here. The "%c" conversion will take *one* byte and
- store it in the address given, which is the address of your short.
-
- Depending on the "byte sex" of your machine, this may be the high or
- low byte (assuming a short is two bytes). The other byte will contain
- garbage, as you haven't given x and y intial values.
-
- What you should do, it to declare x and y as chars, so they will be
- set correctly.
-
- |> menu[j][i] = (short)((y<<8)+x); /* putting together screen
-
- I think you should then move the cast to in front of y:
-
- menu[j][i] = ((short)y<<8)+x;
-
- ---
- Bj|rn P. Munch | Dept. of Comp. Science & Telematics,
- Bjoern.P.Munch@idt.unit.no | Norwegian Institute of Technology (NTH),
- PhD Student | N-7034 Trondheim, Norway
- (some filler words here) | Fingerable addr: bjornmu@multe.idt.unit.no
-