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
arrow
arrow

    mitblog 發表在 痞客邦 留言(0) 人氣()