#include<stdio.h> #include<conio.h> int FindLength(char str[]); // Prototype Declaration void main() { char str[100]; int length; printf("\nEnter the String : "); gets(str); length = FindLength(str); printf("\nLength of the String is : %d",length); getch(); } //Writing function int FindLength(char str[]) { int len = 0; while(str[len]!='') len++; return(len); }
Explanation of the program –
after accepting the string from the user we are passing the complete array to the function.
length = FindLength(str);
Now inside the function we are executing a while loop which will calculate the length of the string.
int FindLength(char str[]) { int len = 0; while(str[len]!='') len++; return(len); }
1 comment:
We can also find length of string using stlen string.h library function.
Post a Comment