Example Source Code:strncpy(參數1,參數2,參數3),指定參數3長度,參數2 複製到 參數1。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char strncpy_a[5]={'a','b','c','d','\0'};
char strncpy_b[5];
strncpy_b[2]=0x00;
strncpy(strncpy_b,strncpy_a,2);
printf("%s",strncpy_b);
return 0;
}
//Answer:
//ab
文章標籤
全站熱搜

留言功能已依作者設定調整顯示方式