home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19284 < prev    next >
Encoding:
Text File  |  1993-01-06  |  1.5 KB  |  53 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!portal!dfuller
  3. From: dfuller@portal.hq.videocart.com (Dave Fuller)
  4. Subject: Re: Hex escaping in strings, (porting from gcc to cc)
  5. Message-ID: <C0ELuw.Hsv@portal.hq.videocart.com>
  6. Organization: VideOcart Inc.
  7. X-Newsreader: Tin 1.1 PL3
  8. References: <1ifpjnINNkck@zephyr.grace.cri.nz>
  9. Date: Tue, 5 Jan 1993 23:13:44 GMT
  10. Lines: 41
  11.  
  12. chrisp@grace.cri.nz writes:
  13. : Hi,
  14. :   I have a problem with porting from gcc to cc (on a sun sparc station)
  15. :         
  16. :     puts("\x1b=");        /* set's the terminals keypad mode */
  17. :  Works fine with gcc, the "\x1b" is interpreted as ascii 27, escape.  But
  18. :  on cc it just prints "x1b=".
  19. :  Is the hex code escape an ansii extension,  how else can I do it?, I would
  20. :  rather avoid:
  21. :     sprintf(tmp,"%c=",27);
  22. :                 Thanks,  Chris.       chrisp@grv.grace.cri.nz
  23.  
  24.    You'll have to forgive me, i dont use gcc, and i dont keep track of
  25. the ANSI standard very well. What you have here is probably an extension 
  26. of gcc. The \ is used to escape n b t and a. Maybe others. It would appear
  27. that gcc added x as an escape for translating hex codes. What you need to
  28. do to make this work is to change the x1b to its octal value. This is 
  29. understood in ANSI C. 
  30.  
  31. so puts("\x1b=")  ---->>>   puts("\033=")
  32.  
  33. to put multiple escape chars together it would be puts("\033\033=");
  34.  
  35. you get the point.
  36.  
  37. chars may be represented as octal values when initialized.
  38.  
  39. char ch_1 = 'X',
  40.      ch_2 = '\130',
  41.      ch_3 = 0130;
  42.  
  43. gives the same value to all of the char variables.
  44.  
  45.  
  46. Dave Fuller
  47. dfuller@portal.hq.videocart.com
  48.  
  49.  
  50.