strncpy and snprintf

 Fri, 19-Sep-2025 12:00:55

strncpy 复制n个字符,n+1后面不会帮你填0(buf[n]是原来的值)

snprintf 第n个填0 ,也就是buf[n-1] = '',返回只是实际字符串的长度。