该函数的作用是计算字符串的长度。
使用方法如下:
#include<stdio.h>
#include<string.h>
int main()
{
char str[] = "abcd";
printf("%d\n", strlen(str));
return 0;
}
用一个自定义函数来实现与strlen函数
#include<stdio.h>
int mystrlen(char* str)
{
int count = 0;
while (*str != '\0')
{
count++;
str++;
}
return count;
}
int main()
{
char str[] = "abcd";
printf("%d\n", mystrlen(str));
return 0;
}