2

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.

5
  • 3
    that is the C++ casting style, it will not work in C. Commented May 29, 2012 at 8:43
  • I don't think that works with multiple token simple-type-specifiers even in C++. Commented May 29, 2012 at 8:44
  • This won't work for C. Guess, in C++ this type of syntax works, considering copy constructor behavoir. Commented May 29, 2012 at 8:49
  • No, doesn't work in C++, and wouldn't involve a copy constructor if it did. Commented May 29, 2012 at 8:51
  • Right. stackoverflow.com/questions/4775781/… Commented May 29, 2012 at 9:35

1 Answer 1

11

Casting is done in parentheses:

 hundreds = (unsigned char)(tick/100); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.