// filename:c2011-K-3-7-1-4-ex.c
// original examples and/or notes:
// 		(c) ISO/IEC JTC1 SC22 WG14 N1570, April 12, 2011
// 			C2011 K.3.7.1.4 The strncpy_s function
// compile and output mechanism:
// 		(c) Ogawa Kiyoshi, kaizen@gifu-u.ac.jp, December.29, 2013
// compile errors and/or wornings:
// 		(c) Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn)
// 			Target: x86_64-apple-darwin11.4.2 //Thread model: posix
// 		(c) LLVM 2003-2009 University of Illinois at Urbana-Champaign.
// Example 1
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
#include <string.h>

int main(void)
{
	/* ... */ 
	char src1[100] = "hello"; 
	char src2[7] = {'g', 'o', 'o', 'd', 'b', 'y', 'e'};
	char dst1[6], dst2[5], dst3[5]; 
	int r1, r2, r3; 
	r1 = strncpy_s(dst1, 6, src1, 100); 
	r2 = strncpy_s(dst2, 5, src2, 7); 
	r3 = strncpy_s(dst3, 5, src2, 4);
return printf("K.3.7.1.4 The strncpy_s function %d %d %d \n",r1,r2,r3 );
}
// output may be