C Program to find the length of String without using strlen

This page has a C Program to find the length of String without using strlen. It is clear that, this C program will find the length of String without using strlen(). String is a set of characters. We can find the length of a given string without using Library functions (String handling functions). For example: If we give the input string as "Christian", the program will count the number of characters in the string and give the output as 9. The below given C program is used to find the length of a given string without using Library functions (String handling functions). Kindly check out the program to find the length of String without using strlen(). The Questions for find the length of String without using strlen problem can be asked as . . . 1). C Program to find the length of String without using strlen() 2). C Program to Find Length of String Without using Library Function 3). C Program to Find the Length of a String without using built-in function 4). C Program to find the length of String without using string function 5). C Program to find the length of String using fgets() 6).C Program to find the length of String using WHILE loop. 7) C Program to find the length of String using DO . . . WHILE loop. 8) C Program to find the length of String using getchar()

length of String without using strlen() Program Using for loop

#include<stdio.h>

int main(){

char word[100];

int i;

printf(" Enter a string: ");

gets(word);

for(i=0;word[i]!='\0';i++);

printf("

Length of given string is: %d",i);

getch();

return 0;

}

length of String without using strlen() Program Using fgets()

#include<stdio.h>

int main(){

char word[200];

int i;

printf(" Enter a string: ");

fgets(word, 200, stdin);

for(i=1;word[i]!=NULL;i++);

printf("

Length of given string is: %d",i-1);

getch();

return 0;

}

length of String without using strlen() Program Using WHILE loop

#include<stdio.h>

int main(){

char word[200];

int i=0;

printf(" Enter a string: ");

gets(word);

while(word[i]!='\0')

{

i++;

}

printf("

Length of given string is: %d",i);

getch();

return 0;

}

length of String without using strlen() Program Using DO . . . WHILE loop

#include<stdio.h>

int main(){

char word[200];

int i=0;

printf(" Enter a string: ");

gets(word);

do

{

i++;

}while(word[i]!='\0');

printf("

Length of string is: %d",i);

getch();

return 0;

}

length of String without using strlen() Program Using getchar ()

#include<stdio.h>

#include<conio.h>

int main(){

char word[200];

int i=0;

printf("Enter a string: ");

while((word[i]=getchar())!='

'){

i++;

}

printf("

Length of string is: %d",i);

getch();

return 0;

}

Sample Output: Enter a string: Christian



Length of string is: 9