avr-gcc-list
[Top][All Lists]
Advanced

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

RE: [avr-gcc-list] Re: Strings: escape sequence to insert arbitrary hex


From: Schwichtenberg, Knut
Subject: RE: [avr-gcc-list] Re: Strings: escape sequence to insert arbitrary hex value ?
Date: Thu, 5 Feb 2009 08:10:32 +0100

As far as I know hex values won't work as expected but octal does!

I used:

static char s46[] __attribute__ ((progmem)) =  "Hei\342gas";            /* 46 */

which is written as "HeiƟgas" on an LCD.

Knut

> -----Original Message-----
> From: 
> address@hidden
> g 
> [mailto:address@hidden
ongnu.org] On Behalf Of Chris Kuethe
> Sent: Thursday, February 05, 2009 8:07 AM
> To: David Brown
> Cc: address@hidden
> Subject: Re: [avr-gcc-list] Re: Strings: escape sequence to 
> insert arbitrary hex value ?
> 
> #include <stdio.h>
> 
> int main(){
>       char *m = "try use 
> \x68\x65\x78\x20\x65\x73\x63\x61\x70\x65\x73\x3f";
> 
>       printf("%s\n", m);
>       return 0;
> }
> 
> On Wed, Feb 4, 2009 at 11:58 PM, David Brown 
> <address@hidden> wrote:
> > Vincent Trouilliez wrote:
> >>
> >> On Thu, 5 Feb 2009 15:18:44 +1030
> >> "Daniel O'Connor" <address@hidden> wrote:
> >>
> >>> You can define it like so..
> >>> #define  LCD_CUSTOM_CHAR_FOO "\012"
> >>>
> >>> then you can do..
> >>> char example[] = "foo" LCD_CUSTOM_CHAR_FOO "bar";
> >>>
> >>> You might be able to do something more clever but I don't 
> know how :)
> >>
> >>
> >> Thanks Daniel (and Ivan as well, off-list), that worked a 
> treat ! :-)
> >>
> >> Only drawback I found, is that I must now have TWO 
> #defines for each and
> >> every custom character: one #define to represent the character as a
> >> string, so I can embed it into a string, and also all the 
> #defines I
> >> already had, which represent the actual numerical value, for when I
> >> need to print an individual/discrete character rather than print a
> >> string. It's not the end of the world, but not very 
> elegant either, so
> >> if anybody has a solution to make do with only one define 
> per character,
> >> I am all ears ;-)
> >>
> >
> > An alternative idea is to find an ASCII character that you 
> don't need
> > otherwise (say, "~"), and use it in your strings.  Then do 
> on-the-fly
> > conversion when outputing the strings:
> >
> > char example[] = "foo~bar";
> >
> > void lcdWriteString(const char* p) {
> >        while (char c = *p++) {
> >                if (c == '~') {
> >                        lcdWriteChar(LCD_CUSTOM_CHAR_FOO);
> >                } else {
> >                        lcdWriteChar(c);
> >                }
> >        }
> > }
> >
> > As long as you don't have too many, the overhead won't be 
> bad (and the
> > substitute characters won't be too confusing).  It should 
> also work with
> > characters >= 128 as the substitutes, I believe.
> >
> >
> >
> >
> >
> > _______________________________________________
> > AVR-GCC-list mailing list
> > address@hidden
> > http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
> >
> 
> 
> 
> -- 
> GDB has a 'break' feature; why doesn't it have 'fix' too?
> 
> 
> _______________________________________________
> AVR-GCC-list mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
> 




reply via email to

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