void printchars()
{
for (x=128;x<224;x++)
write(x);
I want the x to be a char in the write function. How can i change the x to be treated by the write functions as a char, but an int in the loop?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What is the point of making
xanintif you’re just going to strip away its range? That’s what makes this a very strange request. You should just makexaunsigned char—for(unsigned char x = 128; x <224; ++ x) { ....If you just want to ensure you’re calling the
unsigned chartemplate specialization ofwrite<>, then call it like this:write<unsigned char>(x);If not, then you will have to use type casting:
write((unsigned char)x);Edit: I just realized what you might be experiencing. My guess is that you originally used
charbut found something wrong with numbers over 127. You should probably be usingunsigned charforxinstead of eitherintorchar. I edited my answer to accommodate this.charhas a range of -128 to +127.unsigned charhas a range of 0-255.