|ARM Technical Support Knowledge Articles|
Applies to: General Topics
Information in this article applies to:
I'm experiencing trouble using sprintf with an unsigned char variable. The program hangs when I use the # flag with a bx variable type. When I remove the #, the sprintf function executes normally.
Here is my code:
unsigned char x = 0xAA; sprintf(buf, "#02bx", x);
You are trying to print '0xAA' which is four characters, however you have specified a width of only two characters. Sprintf crashes as a result.
Change your line of code to specify a width of four characters:
sprintf(buf, "#04bx", x);
Refer to a good ANSI C book, such as "The C Programming Language" by Kernighan and Ritchie for more information on the # flag.
Article last edited on: 2005-07-19 10:28:45
Did you find this article helpful? Yes No
How can we improve this article?