Exemplo n.º 1
0
Arquivo: t5.5.c Projeto: 4179e1/misc
main()
{
	char s[20];
	char t[] = "orz";
	char u[] = "OTL";
	int n = 5;
	int nx = 2;

	strncpy2(s, t, nx);
	printf("%s\n", s);
	strncpy2(s, t, n);
	printf("%s\n", s);


	strncat2(s, t, nx);
	printf("%s\n", s);
	strncat2(s, t, n);
	printf("%s\n", s);
	
	printf("%d\n", strncmp2(s, t, n));
	printf("%d\n", strncmp2(s, t, nx));
	printf("%d\n", strncmp2(t, s, n));
	printf("%d\n", strncmp2(t, s, nx));
	printf("%d\n", strncmp2(t, u, n));
	printf("%d\n", strncmp2(t, u, nx));

	printf("%d\n", strncmp(s, t, n));
	printf("%d\n", strncmp(s, t, nx));
	printf("%d\n", strncmp(t, s, n));
	printf("%d\n", strncmp(t, s, nx));
	printf("%d\n", strncmp(t, u, n));
	printf("%d\n", strncmp(t, u, nx));
}
Exemplo n.º 2
0
void test_strncat2()
{
	char str1[50] = "Hello ";
	char str2[] = "world!";
	
	printf("strncat2() test:\n");
	printf("Expected result: Hello world!\n");
	printf("Actual result: %s\n", strncat2(str1,str2,6));
	
	printf("\nExpected result: Hello world! You're beautiful.\n");
	printf("Actual result: %s\n", strncat2(str1," You're beautiful.",100));
	printf("*******************************************************\n");
}