#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
unsigned char *str;
unsigned char str1[3];/*注意这里*/
int len;
str="abcdefg";
len=strlen(str);
strncpy(str1,str+2,2);
str1[2]='/0';/*这一句必须要,但是使用strcpy()时不用*/
printf("%d/n",len);
printf("%s/n",str1);
system("pause");
return 0;
}
其实直接用strlen函数就是了,没有想到
c++ 求指针指向的字符串长度
最新推荐文章于 2026-05-23 10:44:25 发布
本文介绍了一个C语言程序示例,该程序演示了如何使用strlen、strncpy等函数处理字符串,并展示了如何正确地为字符数组赋值及终止符的使用。
4510

被折叠的 条评论
为什么被折叠?



