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

Why isn't it being handled properly?

0 Answers  


Can static variables be declared in a header file?

0 Answers  


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?

0 Answers  


What do mean by network ?

0 Answers  


Is c procedural or object oriented?

0 Answers  






What is the sizeof () operator?

0 Answers  


2. Write a function called hms_to_secs() that takes three int values&#8212;for hours, minutes, and seconds&#8212;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.

5 Answers   TCS,


main() { int i = 10; printf(" %d %d %d \n", ++i, i++, ++i); }

10 Answers   TCS, Vector,


main() { float f1=10.5; double db1=10.5 if(f1==db1) printf("a"); else printf("b") }

2 Answers   CSC,


What functions are used for dynamic memory allocation in c language?

0 Answers  


how to print "hai" in c?

13 Answers   TCS,


Why do we need arrays in c?

0 Answers  


Categories