Finding the length of String without using strlen in C

C Program to find the length of String without using strlen

Source code :

#include<stdio.h>

int main(){
    
    char mystring[] = "Hello CodeCry !";
    int length = 0;
    
    while(mystring[length] != '\0'){
        length++;
    }
    

    printf("Length of the given string : '%s' is : %d",mystring,length);

    return 0;

}

Output :

Length of the given string : 'Hello CodeCry !' is : 15

Algorithm :

  1. Create a string mystring and assign a sample value
  2. Create a integer variable length and initialize it to 0
  3. Iterate through the characters in the string and Increment the length if the character is not ie. null
  4. Print the length

Output :


                

Comments :