+ 2

How to count length of string without strlen functions

in Any language u know

3rd Mar 2018, 10:26 AM
StÿLö Tariq
StÿLö Tariq - avatar
12 odpowiedzi
+ 11
C language. : if s is your string ,and l is counter for(i=0;s[i]!='\0';i++)l++; printf("%d",l);
3rd Mar 2018, 10:46 AM
Hannah Grace
Hannah Grace - avatar
+ 14
if u use recursion in place of enhanced for loop in java , then u need to know the no. of elements in char array which will be done by .length method [pre-defined] //so its better to drop that idea , U can think another
3rd Mar 2018, 11:01 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 12
convert user input to char array & then run enhanced for loop 4 it , for each iteartion increase value of a variable i by 1 //final value of i will give length of String //in java[ just thought , on assumption that we can use array & loop]
3rd Mar 2018, 10:53 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 11
what is strlen functions ? //does it mean predefined functions
3rd Mar 2018, 10:41 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 11
\0 is null terminator of a string https://stackoverflow.com/a/14461727
3rd Mar 2018, 11:04 AM
Hannah Grace
Hannah Grace - avatar
+ 3
strlen in javascript is > string.length
3rd Mar 2018, 10:43 AM
caheamt
caheamt - avatar
+ 3
thanx #caheamt
3rd Mar 2018, 10:43 AM
StÿLö Tariq
StÿLö Tariq - avatar
+ 2
foreach(char in string){ count++; } // print count
3rd Mar 2018, 10:41 AM
caheamt
caheamt - avatar
+ 2
yes gaurav its predefined function
3rd Mar 2018, 10:45 AM
StÿLö Tariq
StÿLö Tariq - avatar
+ 2
thanx Hannah grace can u tell me "s[i]!='\0'"<---- it means?
3rd Mar 2018, 10:52 AM
StÿLö Tariq
StÿLö Tariq - avatar
+ 2
i did it with arrey and loop ...but can we do it without using arrey and loop ?
3rd Mar 2018, 10:56 AM
StÿLö Tariq
StÿLö Tariq - avatar
+ 2
recursion ? is it in java
3rd Mar 2018, 10:58 AM
StÿLö Tariq
StÿLö Tariq - avatar