为什么我这个str3打印的是be be #include <stdio.h>
#include <string.h>
int main()
{
char str1[] = "To be or not to be";
char str2[40];
char str3[40];
char str4[3];
strncpy(str2, str1, sizeof(str2));
strncpy(str3, str2, 5);
str3[5] = '\0';
strncpy(str4, str1, 5);
printf("str1:%s--%d\n", str1, strlen(str1));
printf("str2:%s--%d\n", str2, strlen(str2));
printf("str3:%s--%d\n", str3, strlen(str3));
printf("str4:%s--%d\n", str4, strlen(str4));
return 0;
}
str1:To be or not to be--18
str2:To be or not to be--18
str3:be be--5
str4:To be be--8 |