home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11509 < prev    next >
Encoding:
Text File  |  1992-07-23  |  1.7 KB  |  55 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!mcsun!sunic!ugle.unit.no!sigyn.idt.unit.no!bjornmu
  3. From: bjornmu@idt.unit.no (Bj|rn P. Munch)
  4. Subject: Re: Curious bug...
  5. Message-ID: <1992Jul23.114202.1684@ugle.unit.no>
  6. Sender: news@ugle.unit.no (NetNews Administrator)
  7. Organization: Div. of CS & Telematics, Norwegian Institute of Technology
  8. References:  <1992Jul22.050021.3974@uwm.edu>
  9. Date: Thu, 23 Jul 92 11:42:02 GMT
  10. Lines: 43
  11.  
  12. In article <1992Jul22.050021.3974@uwm.edu>, pegasus@csd4.csd.uwm.edu (David R Hucke) writes:
  13. |> Hello everybody!
  14. |> 
  15. |> I have a program that I have written in Quick C 2.5 that doesn't work right and
  16. |> I am stumped.
  17.  
  18. [...]
  19.  
  20. |> #include <stdio.h>
  21. |> 
  22. |> main()
  23. |> {
  24. |> 
  25. |>    short far *SCREEN = (short far *) 0xB8000000;
  26. |>    short menu[8][20];
  27. |>    short x,y;
  28.  
  29. [...]
  30.  
  31. |>            fscanf(file,"%c%c",&x,&y);    /* reading in attribute and
  32. |>                          character bytes */
  33.  
  34. You have a problem here.  The "%c" conversion will take *one* byte and
  35. store it in the address given, which is the address of your short.
  36.  
  37. Depending on the "byte sex" of your machine, this may be the high or
  38. low byte (assuming a short is two bytes).  The other byte will contain
  39. garbage, as you haven't given x and y intial values.
  40.  
  41. What you should do, it to declare x and y as chars, so they will be
  42. set correctly.
  43.  
  44. |>         menu[j][i] = (short)((y<<8)+x);  /* putting together screen
  45.  
  46. I think you should then move the cast to in front of y:
  47.  
  48.            menu[j][i] = ((short)y<<8)+x;
  49.  
  50. ---
  51. Bj|rn P. Munch               | Dept. of Comp. Science & Telematics,
  52. Bjoern.P.Munch@idt.unit.no   | Norwegian Institute of Technology (NTH),
  53. PhD Student                  | N-7034 Trondheim, Norway
  54.  (some filler words here)    | Fingerable addr:  bjornmu@multe.idt.unit.no
  55.