c++ - Why am I getting inconsistent conversions between a binary value and a character? -


working arduino. have following code in function run twice during process:

int hours = 7; char hour = hours+'0'; debug(&hour); char hour2 = hours+'0'; debug(&hour2); 

the debug function is:

void debug(char message[]) {   if (debugenabled == true) {     serial.println(message);   } } 

the global debugenabled flag initialized true.

i'm getting following output every time full process runs (hence executing first code block twice):

7  7  72  7  

i can't see reason i'm getting 72 in there on second time first variable written, hour2 variable printed correctly every time.

any suggestions might going wrong or how further debug appreciated.

because treat single character string. string in c needs terminated '\0' character. string handling functions continue until find terminator character, , go beyond array limits may have , producing unexpected , undefined results.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -