how to generate the length of a string without using len
funtion?

Answers were Sorted based on User's Feedback



how to generate the length of a string without using len funtion?..

Answer / shruti

** same as above.. only u should initialise the valued of
varibale len to 0..
otherwise it will pick up some garbage value.. **


int strlength(char s[])
{
int i , len;

len = 0;
for(i = 0 ; s[i] != '/0' ; i++)
{
len++;
}

return len;
}

Is This Answer Correct ?    8 Yes 0 No

how to generate the length of a string without using len funtion?..

Answer / poornima

#include<stdio.h>
int strlength(char *);
int main()
{
char *str;
int len;
printf("Enter a string : ");
gets(str);
len=strlength(str);
printf("Length of %s is %d",str,len);
return 0;
}
int strlength(char *str)
{
int len=0;
for(;*str!='\0';str++)
{
len++;
}
return len;
}

Is This Answer Correct ?    2 Yes 0 No

how to generate the length of a string without using len funtion?..

Answer / shreesha vailaya


int strlength(char s[])
{
int i,len;
for(i=0;s[i];i++)
len++;
return len;
}

Is This Answer Correct ?    4 Yes 4 No

how to generate the length of a string without using len funtion?..

Answer / dattathreya

The below function should do it:

int strLength(char *s)
{
int i;
for(i = 0; s[i]; i++);
return i;
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

How many ways are there to swap two numbers without using temporary variable? Give the each logic.

9 Answers  


‎How to define structures? · ‎

0 Answers  


Define Array of pointers.

0 Answers  


What does nil mean in c?

0 Answers  


WHY DO WE USE A TERMINATOR IN C LANGUAGE?

2 Answers  


Explain the difference between malloc() and calloc() in c?

0 Answers  


Is c high or low level?

0 Answers  


What is memcpy() function?

0 Answers  


What's the total generic pointer type?

0 Answers  


Program to find largest of three numbers without using comparsion operator?

3 Answers  


What is the difference between int main and void main in c?

0 Answers  


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

0 Answers   Subex,


Categories