Find length of string without built-in function

#include <stdio.h>
 int main()
 {
   char s[1000];
   int i=0;
   printf("Enter a string: ");
   scanf("%s", s);
   while(s[i] != '\0')
   {
      i++;
   }
   printf("Length of string: %d", i);
   return 0;
 }
Explaination of the Program : Here, in this program, we have declared one char data type variable named s and other variable of integer data type which is initialized to 0. Accepting the string from the user of whom the length is to be found. While loop is used and then condition is the loop will until the null character isn't identified. Inside the loop, we are incrementing the value of i and so we can get the value of the length which i itself at the end of the loop.
Previous
Next Post »
0 Comment