not sure why the trailing NULLs are a problem. they probably existed in the memory before program startup, or were initialized in some manner during execution.
the first NULL after "2:00 pm" signals the end of the string. why do you care that there are more than one? anything after the first terminating NULL is not considered to be "extra data"
or am i missing something?
.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
char * strncpy ( char * destination, const char * source, size_t num );
No null-character is implicitly appended to the end of destination, so destination will only be null-terminated if the length of the C string in source is less than num.
http://www.cplusplus.com/reference/clibrary/cstring/strncpy/
In your example strncpy(Hour, ConvertTime, 2); The length of ConvertTime is greater than 2, so the resultant string Hour will not be NULL-terminated. Hopefully, Hour was declared as char Hour[3]; so that it can hold the NULL terminating character.
See the example that was shown in the link I posted above how to fix that problem.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343