In this section, we will write a C program to find the length of a string without using strlen() function. But before, you may go through the following topic in C programming.
The program will take the user input for the string and iterate the string. It will count the number of characters present in the string.
C Program to Find the Length of a String without using Function strlen()
// C program to find length of the string without using strlen() function
#include <stdio.h>
int main()
{
char str[30];
int i;
printf("Enter a string: ");
scanf("%s", str);
for (i = 0; str[i] != '\0'; ++i);
printf("The length of %s is %d", str, i);
return 0;
}
Output:
Enter a string: simple2code
The length of simple2code is 11
You can also check the following: