vc++编程题:设计一个函数,求字符串的长度(指向字符串的指针作为函数的参数)。在

急啊
2025-03-12 03:20:28
推荐回答(1个)
回答1:

#include
#include
#include
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;
}

再来一个:
#include
#include
int test strlen(char *s)
{char *p=s;
while (*p)
p++;
return p-s;
}