[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] C Escape sequence.

From: Joerg Wunsch
Subject: Re: [avr-gcc-list] C Escape sequence.
Date: Thu, 25 May 2006 08:10:32 +0200 (MET DST)

"Royce Pereira" <address@hidden> wrote:

> Sorry for my rusty C, but how does one insert a hex value into a string?
> I tried
> const char messg[] PROGMEM= "Temp=   \xdfC";
> and
> const char messg[] PROGMEM= "Temp=   \xdf\C";

That's the exact reason why C89 invented the feature to concatenate
adjacent strings into one.  You can write

const char messg[] PROGMEM= "Temp=   \xdf" "C";

Or, you could improve readability by

#define DEGREE "\xdf"
const char messg[] PROGMEM= "Temp=   " DEGREE "C";

Hexadecimal or octal escape sequences stop at the first character that
does not belong to their respective character set, that's why your
first variant didn't work (the "C" is a valid hex character).  In
traditional K&R C, there were no hexadecimal escape sequences, and
IIRC octal escape sequences artificially stopped after the third octal

cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]