how do we find the string length without using strlen() function?
how do we find the string length without using strlen() function?
There are many ways of doing it. Just running through the characters of the string inside a for/while loop will do the trick.
Cheers!
Kalayama
[COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR]
Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
char ch[20];
int i=0,len=0
//enter string and store it a array;
while(ch[i]!='\0')
{ len=len+1;
i++;
}
cout<<"length is" <<len;
#include<stdio.h>
#include<conio.h?
void main()
{
char ch[20];//to store string into the arry
int i=0,length=0
while(ch[i]!='\0')// while arry not equal to null. String stores at the end as null
{
length+=1;//length=length+1
i++;
}
printf("The String length is",length);
}
len is used for find the length of the string
char *ch;
gets(ch);
for(int i=0;ch[i]!='\0';i++);
printf("%d",i);
To find length of an array use this
int a;
a=printf("12345");
/* a has length of string "12345" i.e 5
[QUOTE=shivaram.cunchala;12881]how do we find the string length without using strlen() function?[/QUOTby counting the number of character with spaces