C Programming

Program to find String length without using strlen().

Program to find String length without using strlen().
#include <stdio.h>
 
int string_length(char []);
 
int main()
{
   char s[1000];
   int length;
 
   printf("Input a string\n");
   gets(s);
 
   length = string_length(s);
 
   printf("Length of %s = %d\n", s, length);
 
   return 0;
}
 
int string_length(char s[]) {
   int c = 0;
 
   while (s[c] != '\0')
      c++;
 
   return c;
}
Nikhil Juneja

Passionate software developer and technical contributor at TutorialsLink.