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 |
1.What is a Data Structure? Explain its need? 2.What is a Directed Graph? Write an algorithm to find whether a Directed Graph is connected or not? 3.Explain the process of converting a Tree to a Binary Tree.
What is static volatile in c?
What is structure in c language?
What ios diff. Between %e & %f?
why TCS selected more student in the software field from all institution.
What is meant by initialization and how we initialize a variable?
With the help of using classes, write a program to add two numbers.
what is the first address that gets stored in stack according to a C or C++ compiler???? or what will be the first address that gets stored when we write a C source code????????
define c
Find occurence of a character in a sting.
What will be the output of x++ + ++x?
Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?