Problems with printf

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problems with printf

1,719 Views
BairesRobotics
Contributor I

Hello:

I need to print in a LCD this text "200 %4.1f\xD2C" but \xD2C give error. \xD2 is the grad simbol and C for Centigrad. CW meens that \xD2C is an hex number and get error. If I print "\xD2 C" solve the problem, but I must eliminate de space caracter. I have tested with "\xD2""C" but that get "concatenation worning" and compile.

 

Please can any solve this problem ??

 

Thanks

Jorge Migiel Dhios

Labels (1)
0 Kudos
3 Replies

458 Views
Reky
Contributor II

Quick and (very) ugly solutions:

- use two printf's without \n or other esc chars between;

- strcpy the entire output msg in a string and print it out;

- strcpy just the \xD2C as it gets into a string...

 

Don't ask about optimizations on size and speed... :smileyhappy:

 

Regards

0 Kudos

458 Views
Lundin
Senior Contributor IV
ISO C states that hexadecimal escape sequences are only terminated by a non-hexadecimal number. This is idiotic, but it is the standard.

The solution is to trick the IDE into ending the escape sequence for you:

printf("200 %4.1f\xD2" "C", ...);


As long as there is a space between the D2" and the "C" you shouldn't receive any warnings.
Message Edited by Lundin on 2009-06-11 03:40 PM
0 Kudos

458 Views
kef
Specialist I
Yes, there's a problem with \x<hex number>. I don't remember explanation why there's a problem with \x, but using octal number (\322 in your case) should always work. You just need to always specify 3 octal digits after \, for example "\000", "\001", "\002\010" etc. "200 %4.1f\322C" should work properly
Message Edited by kef on 2009-06-10 01:29 PM
0 Kudos