WAP to calculate the length of string using a user-defined function

Write a program to calculate the length of string using a user-defined function

#include<stdio.h>
#include<conio.h>

int length(char[]);

void main() {
	int ln;
	char str[20];

	printf("Enter any string:\n");
	gets(str);

	ln = length(str);
	printf("Length of %s is %d",str,ln);
}

int length(char str[]) {
	int i=0;

	while(str[i]!='\0') {
		i++;
	}
	return i;
}

Output

Enter any string:
nawaraj
Length of nawaraj is 7

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments