Length of string data structure by R4R Team

Here we find the length of the given string without any use of the predefined library.

Example-
string is "r4r_string"
Length is : 10

program-

#include< stdio.h>
int main()
{
char ch[20];
int len=0,i=0;
printf("Enter string\n");
scanf("%s",&ch);
while(1)
{
if(ch[i++]!='')
len++;
else
break;
}
printf("Length of the string is %d",len);
}


output-

Enter string
Mystring
Length of the string is 8

-In this program, we firstly take an input in string(i.e, ch[20]) and run the while loop until the string terminated
-Each iteration of loop increase the value of the variable 'len'
-And at last we have a length of the string in 'len' variable which we display.
-if(ch[i++]!=''), where '' represent the end of the string.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!