Q:

C Program to find length of a string using recursion

0

C Program to find length of a string using recursion

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[100];
 
   gets(s);
 
   printf("Length = %d\n", string_length(s));
 
   return 0;
}
 
int string_length(char *s) {
   static int c = 0;
 
   while (s[c] != '\0') {
      c++;
      string_length(s+1);
   }
 
   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