c-program to calculate the length of the string without using strlen function.
In this program, we will now allow the user to enter the any string or character array and It will gives the length of the string without using strlen function.
string is nothing but one dimensional array of character which is terminated by a null character '\o'.
In this program, we have the length of sting so, we need to loop and count all words and spaces in the loop until '\0' character is matched
#include<stdio.h>
#include<conio.h>
void main()
{
char str[20];
int i;
printf("enter a string\n");
gets(str);
for(i=0;i<str[i];i++);
printf("length of the string is %d",i);
getch();
}
output:-
for more c-programing practice:-
1.c-program to calculate the length of string using strlen function
2.c-program to string into lowercase
3.program to count the vowel in the string.

No comments:
Post a Comment