![]() |
Printf Question
This is probably a dumb question but I dont have as much experience with C as I'd like to :) Is it possible to printf a char as an ASCII character? printf_lib.c says %c is unsupported. But somehow strings enclosed in quotation marks print with no problems. How do I convert a byte to a single-character string?
|
Re: Printf Question
Quote:
|
Re: Printf Question
Unfortuately, this does not seem to work. I get some garbage as output and then the RC locks up. Could you post some example code?
And, actually, this is not really critical :) Its ok if I dont get it working. |
Re: Printf Question
Quote:
|
Re: Printf Question
If you read the file "printf_lib.c" (I think) you will see a comment that says "%c" is not supported. The best you are going to do is put the character into a char array two long setting your character in location 0 and '\0' (or zer0) in location 1, then print it using "%s" as the format and using the array name.
char t [2]; t [0] = 61; // Or what ever you character is. t [1] = '\0' // Null character. printf ("%s\n", t); |
Re: Printf Question
Quote:
|
Re: Printf Question
I actually figured this one out on my own last night :) Sorry forgot to post here.
|
Re: Printf Question
What was the fix, anyway? I like to know so that if I ever get it, I have an idea on what it might be.
|
Re: Printf Question
Actually, the byte array thing worked on MS VC6.0 but didnt in MPLAB :) One way of sending an unsigned char as an ascii character is actually very simple. I just do what printf_lib.c does when sending a byte - assign the unsigned char to the transmit register (I think it is called TXREG) and then call WaitForTXEmpty.
|
Re: Printf Question
Quote:
|
| All times are GMT -5. The time now is 02:51. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi