I'm writing a function that stores an integer as separate bytes in an array, see here.
I've got to the part when I detect a button push, and increment the digit over the cursor. If this digit gets to 9, the next push should reset it back to 0. The following code works:
digit[curpos]++ ; // increment digit
digit[curpos] = (digit[curpos] > 9) ? 0 : digit[curpos] ; // if > 9, reset to 0
However, I figured I could use the remainder, but my code thinks otherwise:
digit[curpos] = ((digit[curpos]++) % 10) ; // doesn't work
An added complication (and the reason I wanted to tidy this up) is that the MSD (in digit[4], so curpos = 4) only has a range of 0 to 3, giving the number a maximum of 39999. I will need to add code to deal with this case later.