Casting to an unsigned char

c, casting, types

Solution

Casting is done in parentheses:

 hundreds = (unsigned char)(tick/100);

Problem

I'm using MPLab C18 C compiler and getting a syntax error with this code: ``` hundreds = unsigned char((tick / 100)); tens = unsigned char((tick - (hundreds * 100)) / 10); ones = unsigned char((tick - (hundreds * 100) - (tens * 10))); ``` `tick` is an `unsigned int`. What I'm attempting is to convert a three digit value over to three individual ASCII values by means of simple division and casting the whole number into my `unsigned char` variables. It looks okay to me but I guess I'm missing something.

Original source

Related problems