Go to Post I volunteered to be the person responsible for the electronics and raised my hand before realizing that I have had almost no electronics experience. I hope our robot turns out alright... - Blue_Mist [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 06-03-2004, 19:17
Greg's Avatar
Greg Greg is offline
Registered User
FRC #1075 (Sinclair Sprockets)
Team Role: College Student
 
Join Date: Nov 2002
Rookie Year: 2003
Location: Whitby, Ontario, Canada
Posts: 108
Greg is on a distinguished road
Send a message via ICQ to Greg Send a message via MSN to Greg
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   Spotlight this post!  
Unread 06-03-2004, 19:23
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Printf Question

Quote:
Originally Posted by Greg
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?
try creating a 1-element char array, and then assigning the value of the byte to the first element (element 0) in the array.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #3   Spotlight this post!  
Unread 06-03-2004, 20:12
Greg's Avatar
Greg Greg is offline
Registered User
FRC #1075 (Sinclair Sprockets)
Team Role: College Student
 
Join Date: Nov 2002
Rookie Year: 2003
Location: Whitby, Ontario, Canada
Posts: 108
Greg is on a distinguished road
Send a message via ICQ to Greg Send a message via MSN to Greg
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   Spotlight this post!  
Unread 06-03-2004, 22:10
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Printf Question

Quote:
Originally Posted by Greg
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.
last i looked, there were functions to output individual bytes and other things to the output window... try the PrintString() function defined in ifi_utilities.h/c
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #5   Spotlight this post!  
Unread 06-03-2004, 22:59
Daniel Daniel is offline
Daniel Katanski
#0240
Team Role: Mentor
 
Join Date: Feb 2004
Location: Monroe, MI
Posts: 32
Daniel is on a distinguished road
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   Spotlight this post!  
Unread 07-03-2004, 00:22
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Printf Question

Quote:
Originally Posted by Daniel
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);
yeah, try that... forgot about the null terminator, because i'm so used to just using strcpy gotten lax.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #7   Spotlight this post!  
Unread 07-03-2004, 13:43
Greg's Avatar
Greg Greg is offline
Registered User
FRC #1075 (Sinclair Sprockets)
Team Role: College Student
 
Join Date: Nov 2002
Rookie Year: 2003
Location: Whitby, Ontario, Canada
Posts: 108
Greg is on a distinguished road
Send a message via ICQ to Greg Send a message via MSN to Greg
Re: Printf Question

I actually figured this one out on my own last night Sorry forgot to post here.
  #8   Spotlight this post!  
Unread 07-03-2004, 21:24
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
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   Spotlight this post!  
Unread 08-03-2004, 01:06
Greg's Avatar
Greg Greg is offline
Registered User
FRC #1075 (Sinclair Sprockets)
Team Role: College Student
 
Join Date: Nov 2002
Rookie Year: 2003
Location: Whitby, Ontario, Canada
Posts: 108
Greg is on a distinguished road
Send a message via ICQ to Greg Send a message via MSN to Greg
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   Spotlight this post!  
Unread 08-03-2004, 06:57
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: Printf Question

Quote:
Originally Posted by Greg
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.
Tricky. That interesting. Thanks for that info.
__________________

Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 03:08.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi