Dotcpp  >  编程教程  >  string.h头文件  >  C语言strlen()函数:计算字符串长度

C语言strlen()函数:计算字符串长度

点击打开在线编译器,边学边练

函数名: strlen

头文件:<string.h>

函数原型: int strlen(const char *str);

功 能: 计算字符串长度

参 数: const char *str  为要计算的字符串

返回值: 返回字符串str的长度


程序例:计算字符串str的长度

#include<stdio.h>

#include<string.h>

int main(void){

   char *str="www.dotcpp.com";

   int len=strlen(str);

   printf("%s的长度为%d\n",str,len);

   return 0;

}

 

运行结果:

"www.dotcpp.com"的长度为14



本文固定URL:https://www.dotcpp.com/course/588

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)