Program to find the length of a string using library function in C

Source Code

// 54.i. Program to find the length of a string using library function
// Arpan Das - CST 2nd Year (VOCLET)

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

int main () {
	char str[50];
	int len;
	//clrscr();

	printf("\t\t..:: find the length of a string using library function ::..\n\n");
	printf("Please enter any string: ");
	//gets(str);
	scanf("%[^\n]%*c", str); // Take string with spaces

	len = strlen(str);

	printf("\nLength of %s is %d", str, len);

	//getch();
	return 0;
}

Output

	..:: find the length of a string using library function ::..

Please enter any string: Hello World

Length of Hello World is 11

Leave a Reply

Note: Your email address will not be published. Required fields are marked *