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 support@ccsinfo.com

sending string and decoding

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



Joined: 14 Jul 2007
Posts: 38

View user's profile Send private message

sending string and decoding
PostPosted: Mon Jan 04, 2010 3:57 pm     Reply with quote

hi everyone,

I am sending serial data to PIC via rs232 port using Visual Basic.
The data is like this "f123k456h789".

I get these data to 18f452 by using gets().

How can I separate this data to:

f,123k,456,h,789

Then I am going to use it in PIC code.

thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 04, 2010 4:02 pm     Reply with quote

See this thread and the link in it:
http://www.ccsinfo.com/forum/viewtopic.php?t=40435


Edit: Corrected the link.


Last edited by PCM programmer on Mon Jan 04, 2010 4:16 pm; edited 1 time in total
ferkar



Joined: 14 Jul 2007
Posts: 38

View user's profile Send private message

PostPosted: Mon Jan 04, 2010 4:11 pm     Reply with quote

Thanks for help. However it is not the answer I want I think. I need to find a command or something like that is used for splitting the string and get the characters that I want.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 04, 2010 4:17 pm     Reply with quote

Sorry. I put in the wrong link. I have corrected it now.
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Jan 05, 2010 12:12 am     Reply with quote

Just out of curiosity, why don't you send the data with the ',' commas in the string?

At that point, loop through all chrs, building a new string, and when you encounter "," process what you have thus far, then continue.

Or do you have a string when each field is separated by ',' and thus not data items? ie: 'username,phone,cell_phone' type of thing?

If the latter is the case, I usually make an array of strings, and parse the string into the array, such as GPS data, then I know which field has the data I want.
_________________
Michael Bradley
www.mculabs.com
Open Drivers and Projects
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

Re: sending string and decoding
PostPosted: Tue Jan 05, 2010 3:24 am     Reply with quote

ferkar wrote:
hi everyone,

I am sending serial data to PIC via rs232 port using Visual Basic.
The data is like this "f123k456h789".

I get these data to 18f452 by using gets().

How can I separate this data to:

f,123k,456,h,789

Then I am going to use it in PIC code.

thanks


This can be very easy or quite complicated, it all depends.
Is each section a fixed length e.g 1 char, 4 chars, 3 chars, 1 char, 3 chars (numbers will have leading 0's 056) ?
Are the numbers to be translated into values (456, 789) ?
Does the k (123k) represent 1024 or 1000 and can there be an m, g ?
Can they be uppercase and do they mean the same thing. ?

The simple solution is to do something like

Code:

char a, b[5], c[4], d, e[4]; // need space for the null terminating for the strings

char s[] = "f123k456h789";

a = s[0];
strncpy(b, s[1], 4;  // Will put a null on the end
strncpy(c, s[5], 3);
d = s[8];
strncpy(e, s[9], 3);

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