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

parsing function

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







parsing function
PostPosted: Fri Apr 28, 2006 5:28 pm     Reply with quote

I have a string "M 1 2 3 4 5 6 7 8 9" that I got from the function gets() (serial communication). Is there a parse function in ccs c that will split the numbers (1,2,3,4..) and put them in an int 9 elements array?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Apr 29, 2006 7:53 am     Reply with quote

I don't think there is a function that will do all you want, but have a look at the standard C function strtok(), this comes very close. Strtok will split your string into 'tokens', giving you a pointer to the first token and on every subsequent call a pointer to the next token. At first use I found this function a bit confusing but study the example code in ex_str.c or search the internet for more documentation.

To use strtok() you will have to include <string.h> in your program.
KamPutty
Guest







Re: parsing function
PostPosted: Sat Apr 29, 2006 10:17 am     Reply with quote

pAces wrote:
I have a string "M 1 2 3 4 5 6 7 8 9" that I got from the function gets() (serial communication). Is there a parse function in ccs c that will split the numbers (1,2,3,4..) and put them in an int 9 elements array?


Just traverse the initial string starting at element 2 [0 based] (the "1"), use the Ascii to string function (atoi) to convert to an int. Then increase the index by 2 and repeat. This is all assuming the string is one space and one digit.

~Kam (^8*
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