![](https://i-blog.csdnimg.cn/blog_migrate/abb7bf4d333716da4dabcef3bce524fc.png)
c 库函数查找字符串
Here you will get C++ program to find length of a string without using library function.
在这里,您将获得C ++程序,无需使用库函数即可查找字符串的长度。
We iterate through the string until null character ‘\0’ is encountered and increase a counter variable for each iteration. Finally print the counter variable, it contains the length of string.
我们遍历字符串,直到遇到空字符'\ 0',并为每次迭代增加一个计数器变量。 最后打印计数器变量,它包含字符串的长度。
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
char a[30];
int i;
cout<<"Enter a string:";
gets(a);
for(i=0;a[i]!='\0';++i);
cout<<"\nLength of the string '"<<a<<"' is "<<i;
return 0;
}
Output
输出量
Enter a string:hello hi
输入字符串:hello hi
Length of the string ‘hello hi’ is 8
字符串“ hello hi”的长度为8
翻译自: https://www.thecrazyprogrammer.com/2011/03/c-program-to-find-length-of-string-2.html
c 库函数查找字符串