strlen ()- 确定字符串长度

格式

#include <string.h>
size_t strlen(const char *string);

语言级别

ANSI

线程安全

描述

strlen() 函数确定 string 的长度,不包括结束空字符。

返回值

strlen() 函数返回 string的长度。

示例

此示例确定传递到 main()的字符串的长度。
#include <stdio.h>
#include <string.h>

int main(int argc, char ** argv)
{
 
  if ( argc != 2 )
    printf( "Usage: %s string\n", argv[0] );
  else
    printf( "Input string has a length of %i\n", strlen( argv[1] ));
}
/******************  If the input is the string  ***********************
*****************"How long is this string?", ******************
******************  then the expected output is:  *****************
 
Input string has a length of 24
*/

相关信息