#include <stdio.h>
void main()
{
char string[50];
int i, length = 0;
printf(“Enter a string\n”);
gets(string);
for (i=0; string[i] != ‘\0′; i++) /*keep going through each */
{ /*character of the string */
length++; /*till its end */
}
printf(“The length of a string is the number of characters in it\n”);
printf(“So, the length of %s =%d\n”, string, length);
}
/*—————————————————-
Output
Enter a string
hello
The length of a string is the number of characters in it
So, the length of hello = 5
RUN2
Enter a string
E-Commerce is hot now
The length of a string is the number of characters in it
So, the length of E-Commerce is hot now =21
———————————————————-*/
Not Satisfied ? Just search & get the result
Related posts:
- Sample – Program to enter a string and find its length.
- C Program to accepts two strings and compare them. Finally it prints whether both are equal, or first string is greater than the second or the first string is less than the second string
- C program to read a string and check whether it is a palindrome or not (without using library functions). Output the given string along with suitable message.
- C Program to accept two strings and concatenate them i.e.The second string is appended to the end of the first string
- C program to read two strings and concatenate them (without using library functions). Output the concatenated string along with the given string
