>
> Since you already have the information in the buffer, you need to
> examine each digit and add them together with the correct
multiplier.
> You might have to get fancy to determine the number of digits. To
get
> the digit from ASCII to decimal, simply subtract 48 from the value
and
> there you go. Now start right to left and add the Right*(10^0) +
> (Right-1)*10^1 + (Right-2)*(10^2)... Until you get to the left
digit.
> One possible method would be to find the space and then work
backwards
> from there adding the digit and the multiplier. If you need some
help
> with the code, let me know and I will try to help you.
>
>
Yes, you are going to have to do this the hard way. When you read
the 'T', you know to expect 2 numbers potentially starting with a
space (between T and the first number) ending in a space or some
combination of CR or LF.
So, when you detect the 'T', set both variables to 0. Now, as you
read the first digit, multiply the first variable by 10 and add in
the new digit (calculated as the ASCII val - '0'). Keep going, digit
by digit, until you encounter a space. Now start converting the
second number in the same manner until you get a space, CR or LF. In
fact, you should terminate conversion when you detect a non-digit,
regardless of what it is.
This should not require a buffer if you can act quickly enough on the
incoming chars. If not, go ahead an put the chars in a buffer and
work through the buffer from left to right as indicated above.
Richard
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/oopic/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/oopic/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:oopic-digest@yahoogroups.com
mailto:oopic-fullfeatured@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
oopic-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
No comments:
Post a Comment