" 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
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
Input Cleanup
Posted: Tue Feb 08, 2005 10:29 am
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
Posted: Tue Feb 08, 2005 10:53 am
thank you dyeatman:
yes , I want to round it over.
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
Posted: Tue Feb 08, 2005 11:50 am
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.
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