Program to Calculate Length of a String (Using strlen in-built function)
#include#include #include void main(){ int strlength; char *str; clrscr(); printf("\nEnter the string: "); gets(str); strlength=strlen(str); printf("\nThe length of the string is %d.",strlength); getch(); }
Output:
Enter the string: Learn C Online
The length of the string is 14.
thanx
plz post for Without using strlen().
#include
#include
int string_ln(char*);
int main()
{
char str[20];
int l;
printf(“Enter any string:n : “);
gets(str);
l=string_ln(str);
printf(“The length of the given string %s is : %d”,str,l);
getch();
}
int string_ln(char*p) /* p=&str[0] */
{
int count=0;
while(*p!=’\0′)
{
count++;
p++;
}
return count;
}