Chef Flambe
Chef Flambe

Reputation: 883

Casting to an unsigned char

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.

Upvotes: 2

Views: 6505

Answers (1)

MByD
MByD

Reputation: 137422

Casting is done in parentheses:

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

Upvotes: 11

Related Questions