char change

How to convert int into char and dispaly it with serialport ?

unsigned char x=198;
char hello[3];

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    hello[0]=(char)(x/100);
    hello[1]=(char)(x/10%10);
    hello[2]=(char)(x%10);
    Serial.print(hello[0]);
    Serial.print(" ");
    Serial.print(hello[1]);
    Serial.print(" ");
    Serial.println(hello[2]);
    delay(500);
}

but it display nothing . why ?

but it can't display . why ?

Nothing displays? I would expect that you would see the value 198, but then nothing else.

The value 198/100 results in 1, which you cast as a char. The value 1, as a char, is a non-printing character. It is NOT a '1'. The same holds true for 9 and 8.

As a hint, 1 + '0' = '1'.

Fortware:
How to convert int into char and dispaly it with serialport ?

unsigned char x=198;

char hello[3];

void setup()
{
    Serial.begin(9600);
}

void loop()
{

hello[0]=(char)(x/100);
    hello[1]=(char)(x/10%10);
    hello[2]=(char)(x%10);
    Serial.print(hello[0]);
    Serial.print(" ");
    Serial.print(hello[1]);
    Serial.print(" ");
    Serial.println(hello[2]);
    delay(500);
}



but it can't display . why ?

I do as you say . the first result is right , the rest of it is wrong .
Can you tell me the reason ?

char x=126;
char hello[3]={'0','0','0'};

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    hello[0]+=(char)(x/100); 
    hello[1]+=(char)(x/10%10);
    hello[2]+=(char)(x%10);
    Serial.print(hello[0]);
    Serial.print(" ");
    Serial.print(hello[1]);
    Serial.print(" ");
    Serial.println(hello[2]);
    delay(500);
}

Thanks very much .

    hello[0]+=(char)(x/100); 
    hello[1]+=(char)(x/10%10);
    hello[2]+=(char)(x%10);

The first time loop() runs, hello will contain '1', '2', and '6'.

The next time, it will contain '2', '4', and '<'.

The next time, it will contain '3', '6', and 'C'.

This hardly seems like the thing you want to be doing. Though it is not clear what you want to be doing.