Q:

C Program to find String length without using strlen()

0

C Program to find String length without using strlen()

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#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;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now