strlen() – C语言库函数
C库函数 size_t strlen(const char *str) 计算字符串str的长度,但不包括终止空字符。
声明
以下是声明的strlen() 函数。
size_t strlen(constchar*str)
参数
-
str -- 这是字符串的长度要计算的。
返回值
这个函数返回字符串的长度。
例子
下面的例子显示使用strlen() 函数。
#include<stdio.h>#include<string.h>int main (){char str[50];int len; strcpy(str,"This is xyhtml5.com"); len = strlen(str); printf("Length of |%s| is |%d| ", str, len);return(0);}
让我们编译和运行上面的程序,这将产生以下结果:
Length of |This is xyhtml5.com| is |26|