Monday, March 5, 2012

No, strncpy() is not a "safer" strcpy()

The C standard library declares a number of string functions in the standard header <string.h>.

By the standards of some other languages, C's string handling is fairly primitive. Strings are simply arrays of characters terminated by a null character '\0', and are manipulated via char* pointers. C has no string type. Instead, a "string" is a data layout, not a data type. Quoting the ISO C standard:

A string is a contiguous sequence of characters terminated by and including the first null character.