Is snprintf() ALWAYS null terminating?
问题 Is snprintf always null terminating the destination buffer? In other words, is this sufficient: char dst[10]; snprintf(dst, sizeof (dst), \"blah %s\", somestr); or do you have to do like this, if somestr is long enough? char dst[10]; somestr[sizeof (dst) - 1] = \'\\0\'; snprintf(dst, sizeof (dst) - 1, \"blah %s\", somestr); I am interested both in what the standard says and what some popular libc might do which is not standard behavior. 回答1: As the other answers establish: It should: snprintf