??? 03/03/10 21:08 Read: times |
#173799 - Think about it... Responding to: ???'s previous message |
Munish Kumar said:
I strongly suspected that it had something to do with null termination of the string. Didn't you notice, then, in the debugger that the NUL termination was missing? But I kept on thinking it was the job of the compiler to terminate strings with a null char. What made you think that? The Standard Library Function generally add a NUL termination if required - but you were building this string yourself - so it is up to you to build it properly! Anyways the problem is solved by changing buffer[2] to buffer[3] & assigning last byte 0. Correct - you must always make your arrays big enough to hold the NUL terminator! And also doesn't strcat() append a null char to destination string? Well, you can say that it appends a "new" NUL, or you can say that it copies the original NUL; the effect is identical - and, if the original NUL is missing, there will be trouble! Think what happens when the original NUL is missing - how will strcat() know when to stop copying and, therefore, when to "append" its NUL...? |