We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I want to print in a terminal the "%"character when I put printf(" %c % ",var); the % doesn't print why??
add a \ in front of the special character,like this
printf("%c\%",'c');
c%
"the % doesn't print why??" Because '%' flags the start of a conversion specification in the format string. Check your C books and manuals. They'll show you that for printf() to emit a '%', you must use "%%" in the format string, so your example should be:
printf(" %c %% ",var);
printf("%c\%",'c'); result: c% Bzzzzt! Wrong. I'm kind of guessing, but you didn't test that, did you?
I test both of the senctence in TC
printf("%c%%",'c'); printf("%c\%",'c');
If you are getting "c%" from
"At the printf() sentence,it couldn't jump out,as TI never became 1. what's the reason?" Purely a guess, since you have not shown your UART initialization code, but your UART is not initialized properly or you have not set the TI bit in initialization (as required by Keil's putchar routine, presuming that's what you are using).