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 |
Why isn't it being handled properly?
Can static variables be declared in a header file?
Write a C program on Centralized OLTP, Decentralized OLTP using locking mechanism, Semaphore using locking mechanism, Shared memory, message queues, channel of communication, sockets and a simple program on Saving bank application program using OLTP in IPC?
What do mean by network ?
Is c procedural or object oriented?
What is the sizeof () operator?
2. Write a function called hms_to_secs() that takes three int values—for hours, minutes, and seconds—as arguments, and returns the equivalent time in seconds.. Create a program that exercises this function by repeatedly obtaining a time value in hours, minutes, and seconds from the user (format 12:59:59), calling the function, and displaying the value of seconds it returns.
main() { int i = 10; printf(" %d %d %d \n", ++i, i++, ++i); }
main() { float f1=10.5; double db1=10.5 if(f1==db1) printf("a"); else printf("b") }
What functions are used for dynamic memory allocation in c language?
how to print "hai" in c?
Why do we need arrays in c?