Find the length of a string - String - String - C Language
2301
Arnab De
13/04/2019
Find the length of a string
To find out the length of a string, we follow the following step -
- Declare a counter variable with default value 0
- Read the String
- Travel the string, until the '\\0' character return.
- Print the counter value as string length
int main()
{
char str[30],i,cnt=0;
printf("Enter A String: ");
gets(str);
for(i=0;str[i]!='\0';i++)
{
cnt++;
}
printf("Length of the string is %d",cnt);
return 0;
}