Write a C Program to find the Length of a String

Length of a String


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;



 printf("Length of string is: %d",i);



Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C