将 字符串 赋给char[] :
/* code not tested */
#include <string.h>
int main(void) {
char *src = "gkjsdh fkdshfkjsdhfksdjghf ewi7tr weigrfdhf gsdjfsd jfgsdjf gsdjfgwe";
char dst[10]; /* not enough for all of src */
// strcpy(dst, src); /* BANG!!! 这个是不对的,会越界!*/
strncpy(dst, src, sizeof(dst) - 1); /* OK ... but `dst` needs to be NUL terminated */
dst[9] = '\0';
return 0;
}
----