I'm having trouble using variables in place of numeric values for characters in printf statements.
For example, printf("%c", 201)
displays ╔ as I want it to but printf("%c", var)
when var
is of type char
and var=201
displays ♫.
Anyone have any information as to what's going on?
In fact if there is no l
modifer the argument is converted to unsigned char
so that's why you didn't observe any change when you changed your variable types, what you actually need is
printf("%lc", var);
but in
signed char var = 201;
overflow indeed occurs, so you should be careful.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.