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 |
.find the output of the following program? char*myfunc(char*ptr) { ptr +=3; return (ptr); } int main() { char*x,*y; x="HELLO"; y=myfunc(x); printf("y = %s ",y); return 0; }
Write a c code segment using a for loop that calculates and prints the sum of the even integers from 2 to 30, inclusive?
to print the salary of an employee according to follwing calculation: Allowances:HRA-20% of BASIC,DA-45% of BASIC,TA-10%. Deductions:EPF-8% of BASIC,LIC-Rs.200/-Prof.Tax:Rs.200/- create c language program?
What is the size of enum in bytes?
What is the difference between array and pointer?
what is mallloc()?how it works?
where do we use structure pointer?
What are external variables in c?
main() { char *p; p="Hello"; printf("%c\n",*&*p); }
What is the best style for code layout in c?
Given a single Linked list with lakhs of nodes and length unknown how do you optimally delete the nth element from the list?
What is the best way to store flag values in a program?