int snprintf(char *restrict buf, size_t n, const char * restrict??format, ...);
函數(shù)說(shuō)明:最多從源串中拷貝
n
-
1
個(gè)字符到目標(biāo)串中,然后再在后面加一個(gè)
0
。所以如果目標(biāo)串的大小為
n
???????????????? 的話,將不會(huì)溢出。
函數(shù)返回值:若成功則返回欲寫入的字符串長(zhǎng)度,若出錯(cuò)則返回負(fù)值。
Note:
???gcc下安全, VC下仍要注意
References:
平臺(tái)間函數(shù)差異與系統(tǒng)移植:snprintf/_snprintf
談?wù)剆nprintf
strncpy, strncat和snprintf的區(qū)別
posted on 2008-09-03 13:43
季浩 閱讀(2527)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
心得體會(huì)