Problem with print out a char data type via serial

Hi to all,

I’ve experienced a very strange problem with printing out a variable via serial com.
In the following code you can see a char data type called “ch” which is definitely not empty,
but the Serial.println(ch); command print out nothing, while the rest print out the correct values
including the char array members . Does anyone had the same problem ever?
Thanks for your help in advance!

cheers, Krisztian

#include <string.h>    

const char button = 22;   
float offset;
String offsetString;
char chArray[14]={"this is a test"}, ch = 0;

void setup() {
Serial.begin(9600);
pinMode(button, INPUT);
}

void loop() {
  if(!digitalRead(button)){
    while(!digitalRead(button));
    ch++;
    if(ch > 10) ch = 10;
    offset = ch * 0.5;
    offsetString = String(offset,1);
    for(int i=0; i<15; i++){
      Serial.print(chArray[i]);
    }
    Serial.println();
    Serial.println(offsetString);
    Serial.println(ch);   
  }
}

The code posted does not compile. Too many characters in the chArray initializer.

    Serial.println(ch);

What do you expect to see printed when the value of ch starts at zero and is incremented and never goes higher than 10 ?

    offset = ch * 0.5;ch is a char which is effectively a byte. offset is a float. Can you see a problem ?

Hi,

Thanks for your response. The code compiles successfully on Arduino 1.8.1 for me, however its just an example
to show the problem. The code posted above worked with the "byte" data type but not with "char" thats why I'm confused a bit.

UKHeliBob:
What do you expect to see printed when the value of ch starts at zero and is incremented and never goes higher than 10 ?

it is a good question...

csankok:
...well the problem is more complex:
because the lcd.print(ch); returns the correct value for "ch" just the
serial.print(ch); not work in this case, thats why I'm confused.

What LCD?

On a 2*16 char LCD, the other variables holds the correct value as well, every time. Strange…

csankok:
On a 2*16 char LCD, the other variables holds the correct value as well, every time. Strange...

this phantom LCD isn't in your code, so your point?

Ohh... now I understand:
the Serial.print(); command for a char type returns the corresponding ASCII character.
Thanks for your help guys!

cheers,