C++ Program To Find The String Lenght of The Input String

Leave a Comment
/*C++ program to find the length of user entered string. In this program we have used the two properties of Strings 1. The NULL character ( '\0' ) marks the end of the string and the special property of character array in which character identifier represents the address of first element of the character array(i.e string).*/

#include <iostream.h>            //For Input/Output Stream Related Functions 
#include <conio.h>                  //For Console Input/Output function like clrscr & getche #include<stdio.h>

int slen(char *s)            //Defining the function to find the input string length 
{
{

int i=0,l=0;
while(s[i]!='\0')
{
i++;
// if(s1[i]==' ') /* Uncomment these two lines to omit spaces between the strings in length calculation */
// continue;
l++;
}
return(l);
}


void main()
{
char s[20];
int length;
cout<<"Enter the String ";
gets(s1);
cout<<"Length of String = "<<
slen(s);<<endl;
getche();
}

0 comments: