Header Ads

16 - WAP to Find the Length of given String without using strlen() in C

This program prints the Length of any given String without using strlen() function.

//Program to Find the Length of String
#include <stdio.h> 
//Main Function Program.
int main()
{
   //Declaring the String 
   char scr[1000]; 
   int idx = 0;
   printf("Enter a String : ");
   scanf("%s", scr);
   //Caluclating the Length of String.
   for (idx=0; scr[idx] != '\0'; idx++);
   printf("The Length of String is : %d\n", idx);
 return 0;
} 

Program Output:

No comments