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

来源:百度知道 编辑:UC知道 时间:2024/05/21 21:35:35
急啊

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

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