??? 03/03/10 18:48 Modified: 03/03/10 18:52 Read: times |
#173793 - Null termination Responding to: ???'s previous message |
I strongly suspected that it had something to do with null termination of the string. But I kept on thinking it was the job of the compiler to terminate strings with a null char.
Anyways the problem is solved by changing buffer[2] to buffer[3] & assigning last byte 0. But while debugging, when the "sick" string "11:22:33" formed with repeatedly concatenating 2 bytes of buffer[] was passed to LCD_sendstring(), the LCD_sendstring() actually exited after passing the last '3' to lcdchar(): void LCD_sendstring(char * message) //good 'ol LCD_sendstring { while (*message) // Write message to LCD lcdchar(*message++); }and that was what made my day suck. And also doesn't strcat() append a null char to destination string? Page 313 of Cx51 Compiler User’s Guide says so! "Description: The strcat function concatenates or appends src to dest and terminates dest with a null character." Same is the case with strcpy(). I initialized str_buffer with all 'A's & then after copying & appending the "sick" string, str_buffer still contained a null char. Refer screenshot [108 KB]: http://i782.photobucket.com/albums/yy108/munish4u911ex/keil.png So as soon as LCD_sendstring() should find a null char in str_buffer it should stop printing & exit. Isn't it? Jan Waclawek said:
Munish Kumar said:
convert BCD to decimal (12:34:56 in BCD to 12:34:56 in dec) & then that decimal to an ASCII string Unless this is an exercise in conversions, this double conversion is unnecessary - converting from BCD directly to ASCII is comfortable enough. JW Yes I know, but I need both data types & conversions in my much bigger code, so didnt feel like writing a dedicated third one just for this. And I also knew that it was problem with the code only. I never blamed the compiler or 8051 ;-) |