![Write a C Program to find the Length of a String Length of a String](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgEEuiVQujzDYGlv1PMDzDKYb5ozvCbIjo_Mt3FOu_A8h6GVex9UkCglRQEuc0wTKxbm_OgzCSMsAl0xTsTrdYwnZVmL3fFis99MAlE7B7SZTE3u-l8-Yoy14a7zhjLCMXS_y2grkLeaBz/s1600/c-programming-tutorial.jpg)
#include<stdio.h>
void main()
{
char str[100];
int i;
printf("Please enter a string: ");
// gets(str);
// fgets is a better option over gets to read multiword string .
fgets(str, 100, stdin);
// Following can be added for extra precaution for '\n' character
// if(str[length(str)-1] == '\n') str[strlen(str)-1]=NULL;
for(i=0;str[i]!=NULL;i++);
i=i-1;
printf("Length of string is: %d",i);
}
0 Comments