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

parse 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

parse data
PostPosted: Tue Feb 08, 2005 9:51 am     Reply with quote

I have following data set:

" 81.39375 74.79179 126.0734 126.41383 111.71597 112.42374 112.5276 113.128"
I want to parse the data (get rid of the too many spaces and separate them and reorganized them into

" 81.39 74.79 126.07 126.41 111.72 112.42 112.53 113.13"

How could I do it?
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

Input Cleanup
PostPosted: Tue Feb 08, 2005 10:29 am     Reply with quote

For the spaces, as the data comes in all you have to do is compare the current incoming char to the previous char. If the current is a space and the previous is a space then dump the current char. That always leaves you with one space.

Are you wanting to round up/down the remainders or simply truncate? It looks like you want to round...
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Tue Feb 08, 2005 10:53 am     Reply with quote

thank you dyeatman:

yes , I want to round it over.
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Feb 08, 2005 11:50 am     Reply with quote

If you are going to keep the data in ascii format then about the cleanest way is to format it as the data comes in.

Here is an outline of the way I did it on one similar project:

1. When a decimal point comes in I set a DP (decimal point) flag
2. I then start a digit counter to count the digits that follow.
3. if DP is set and my digit counter =2 I test the char > 5 (0x53h)
4. If > 5 then I increment the 2nd digit by one else I leave it the same.
5. After the increment test to make sure it doesnt roll over to zero.
6. If the digit counter is > 2 then I throw away all chars that come in after that until I see a space then I reset the DP flag and digit counter and start over looking for the decimal point again.

You can combine this with the space test above to make one simple routine. Since you are watching for a space anyway to end the sequence it works right in.

The big advantage of this approach is it minimizes the usage of RAM resources.
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