how to generate the length of a string without using len
funtion?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
How many ways are there to swap two numbers without using temporary variable? Give the each logic.
How to define structures? ·
Define Array of pointers.
What does nil mean in c?
WHY DO WE USE A TERMINATOR IN C LANGUAGE?
Explain the difference between malloc() and calloc() in c?
Is c high or low level?
What is memcpy() function?
What's the total generic pointer type?
Program to find largest of three numbers without using comparsion operator?
What is the difference between int main and void main in c?
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.