How to write a program in c for getting the length of a string without using the function STRLEN?

With the program

Questions by slitherin

Showing Answers 1 - 6 of 6 Answers

angayarkanni packiam

  • Aug 28th, 2007
 

void main()
{
   char s[10];
    int i;
   scanf("%s",s);
   for(i=0;s[i]!='';i++);
   printf("The length of the given string",--i);
   getch();
}

thank you!!!!!!!!!!!!
     

  Was this answer useful?  Yes

pavlov

  • Jun 11th, 2010
 

You will have to write your own implementation of strlen() function in order to get the length of a string.It is not worthwhile to write your own function, as the library functions are really efficient and reusable for standard operations.


int mystrlen(char *s) {

 char *ptr = s;
 int count = 0;

 while (*ptr != '/0') {
    count++;
    ptr++
 }
 return count;
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions