CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Are there same function as printf to receive data?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

Are there same function as printf to receive data?
PostPosted: Thu Aug 12, 2004 6:23 am     Reply with quote

printf("data: %f %i",a, b) send data to RS232 port, on the other side, I receive the sended data as ASCII data, How I can interpret them into a float and a int data.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 12, 2004 6:36 am     Reply with quote

The C function for that would be scanf(). I am not sure if CCS has this function. You will just have to look to see.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 12, 2004 6:43 am     Reply with quote

There are also other functions to convert strings to number

atoi()
atol()
...
See the manual for more
Ttelmah
Guest







Re: Are there same function as printf to receive data?
PostPosted: Thu Aug 12, 2004 6:44 am     Reply with quote

young wrote:
printf("data: %f %i",a, b) send data to RS232 port, on the other side, I receive the sended data as ASCII data, How I can interpret them into a float and a int data.

In normal C, the 'inverse' function, is sscanf. The problem is that as you will have allready found, if you look at the code sizes generated by printf, 'general purpose' functions, tend to be bulky. There have been some implementations of sscanf published in the past, but generic versions tend to be large. However if your string is in a relatively simple 'known' format (which your question suggests), then the answer is to use the standard string functions, then search the string for the character that seperates the two numbers, take the section in front of this, and use the STRTOD function to convert this to a float, then use the STRTOL or STRTOUL function on the rest of the string, to change this into a (long) integer.

Best Wishes
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Thu Aug 12, 2004 6:48 am     Reply with quote

It is nt defined in CCS, so any other ways?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 12, 2004 6:53 am     Reply with quote

Are you handling a single case or do you require a general purpose function to handle multiple cases. For a single case (or just a case) Ttelmah suggestion is the way to go. If you can afford the overhead and require multiple cases, then implement the sscanf() yourself. I have written a sscanf() for the C18 compiler. It uses variable arguments which I don't think CCS supports. I could probably change it around a bit to work with CCS but search the forum and see if someone has already posted one. If not, then maybe I'll put one in the code section.
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Thu Aug 12, 2004 7:02 am     Reply with quote

Thank you Mark:
A special case solution will not be a bad idea for current use, but if you developed any general purpose function, it will be great, Waiting for your code!
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Thu Aug 12, 2004 7:32 am     Reply with quote

Hi Ttelmah:
Do you have any code that separate the string into different part?

thank you
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 12, 2004 7:38 am     Reply with quote

To find a string in a string CCS has a function strstr()
To break up a string based on tokens use strtok()
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Aug 13, 2004 2:12 pm     Reply with quote

Code is in the Library.

http://www.ccsinfo.com/forum/viewtopic.php?t=20225
DragonPIC



Joined: 11 Nov 2003
Posts: 118

View user's profile Send private message

gets()
PostPosted: Tue Aug 17, 2004 2:03 pm     Reply with quote

I would use:
Code:

gets(floater);
gets(interger);
atoi(interger);
atof(floater);
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group