what happens when you use negative operators with %. example -3%2 or 3%-2
In C99 a % b has the sign of a, pretty much like fmod in math.h. This is often what you want :
unsigned mod10(int a) { int b = a % 10; return b < 0 ? b + 10 : b; }