Linux 拨号vps windows公众号手机端

C语言如何获取字符串长度

lewis 6年前 (2019-03-17) 阅读数 13 #程序编程

C语言中可以使用strlen()函数来获取字符串长度。该函数需要一个字符串作为参数,返回值为该字符串的长度(不包括字符串末尾的’\0’)。

例如:

#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello, world!";
int len = strlen(str);
printf("The length of the string is %d\n", len);
return 0;
}

输出结果为:

The length of the string is 13
版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门