Length of the string ?

#include <iostream>
using namespace std ;
//Instead of using length functon you can use a inbuilt function called 'strlen' but if you want to
//use it then you must include <cstring> library. Program will become lot easier.
int length(char input[]) {
int count{0};
for (int i = 0; input[i] != '\0'; ++i) {
count ++ ;

}
return count ;


}

int main(){
char name[100] ;
cout << "Enter your name :" ;
cin >> name ;
cout << length(name);

return 0 ;
}

Comments

Popular posts from this blog

CodeChef::CSUB

How Recursion Works?

CodeChef::TREE2