Monday, October 29, 2018

Finding Length of string using user defined functions

#include<iostream>
using namespace std;
int u_strlen(char s[])
{int i;
 for(i=0; s[i]!='\0'; i++);  // starts from first character till last
    return i; // return strlen
}
int main()
{
    // declare the string
    char name[40];
    //accept the string
   // cin>>name; // ignore space in between
    cin.getline(name,40); // accept space also
            cout<<name <<endl; // display string
    int len=u_strlen(name);
cout<<"Length of String is "<<len<<endl;
//display string in reverse order
for(int k=len-1;k>=0;k--)
cout<<name[k]<<endl;
    system("pause");
    return 0;
}
   
   
   
   
   
   
    

No comments:

Post a Comment