|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
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? |
|
#2
|
||||
|
||||
|
Re: Printf Question
Quote:
|
|
#3
|
||||
|
||||
|
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. |
|
#4
|
||||
|
||||
|
Re: Printf Question
Quote:
|
|
#5
|
|||
|
|||
|
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); |
|
#6
|
||||
|
||||
|
Re: Printf Question
Quote:
gotten lax. |
|
#7
|
||||
|
||||
|
Re: Printf Question
I actually figured this one out on my own last night
Sorry forgot to post here. |
|
#8
|
||||
|
||||
|
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.
|
|
#9
|
||||
|
||||
|
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. |
|
#10
|
||||
|
||||
|
Re: Printf Question
Quote:
That interesting. Thanks for that info. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MIM's question of the day on programming. | Gene F | Programming | 3 | 24-02-2004 16:32 |
| A question about control system options | computhief263 | Control System | 7 | 04-02-2004 14:46 |
| MnM EASY Question of the Day Winners! | Mike Bonham | General Forum | 22 | 03-05-2002 21:21 |
| Chief Delphi Site Question | Mike Bonham | General Forum | 1 | 16-02-2002 22:18 |
| Rookie Programmer has question about the default code | DanL | Programming | 3 | 26-01-2002 19:59 |