#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++ 求指针指向的字符串长度
最新推荐文章于 2024-07-31 14:56:26 发布