Author
Topic: Problem with using uint8_t (Read 829 times)

I am having a little problem using uint8_t in my code and am not sure how to go about it since I am not as familiar with C++ as a lot of the rest of you.

I am using webbotlib in AVR Studio and am using uint8_t to store numbers inputted through a keypad. The keypad is wired correctly and all the right numbers show up and are stored correctly when buttons are pressed.

What I having problems with is determining the length of the stored number. When the number is 3 characters long (i.e.:123), I want the code to do something, thus...

You could use some kind of routine (like rprintf) to print the number as a string and see how long it is - but that WONT work if the user starts their number with a zero. ie What happens if their number is '000'.

So you are much better off keeping track of the number of entered digits in your software that monitors each key press: ie +1 for each key press, set to 0 if the hit the clear button, -1 if they hit backspace.

( So its not an 'uint8_t problem' - its more of a 'How do I track the number of digits entered via a kbd' kinda problem )

I don't have a clue why that did not even occur to me. I'm so used to doing stuff like 'variable.length' for what I am trying to accomplish that I did not even consider something for which I would normally use to check for value within a range.