Quote Originally Posted by Eri523 View Post
Right, however, this is Win32 API. To avoid dependency on Win32, strcpy_s() from the C++ runtime library can be used as an alternative. It's still MS-specific (AFAIK), however.
Yes, it's an MS-specific recommendation that never made it to the new C11 standard. The C standard has had strncpy for years. Use that, if you desire fixed length fields... Just be aware that unlike the non-portable strcpy_s, strncpy might not append a null terminator to the end of your string. If you want that guarantee, end your fixed length field one byte earlier and put the terminator there yourself.

Code:
#include <string.h>
int main(void) {
    char fubar[6];
    strncpy(fubar, "hello world", sizeof (fubar) - 1);
    fubar[sizeof (fubar) - 1] = '\0';
    printf("fubar contains: %s\n", fubar);
    return 0;
}