How to find length of string without using Strlen Function
Here you will get the program code to find length of string without using Strlen Function in C++ programming language. This program can be done by using strlen built-in function and without using strlen function. Here we will be doing this program by without using strlen function.
Program Code to find length of string without using Strlen Function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include<iostream> #include<string.h> using namespace std; int length(char st[]) { int i; for (i = 0; st[i] != '\0'; i++); return i; } int main() { char st[100]; int len; cout<<"\n\tEnter any string to find length : "; gets(st); len = length(st); cout<<"\n\n\tLength of string is = "<<len; return 0; } |
Output
Enter any string to find length : Welcome to coderevise.com
Length of string is = 25
Check out our other C++ programming Examples