In this program, you'll learn how to print the largest string among two strings. First we find the length of both strings, then check which string length is greater, finally we will get the larger string. The strlen() is the C library function which is used to calculate the length of a given string. The function definition of strlen() is: size_t strlen(const char *str)
#include<stdio.h>
#include<string.h>
void main()
{
char str1[20],str2[20];
int len_a,len_b;
printf("Enter first string: ");
scanf("%s", str1);
printf("Enter second string: ");
scanf("%s", str2);
len_a = strlen(str1);
len_b = strlen(str2);
if(len_a > len_b)
{
printf("\nThe larger string is: %s", str1);
}
else
{
printf("\nThe larger string is: %s", str2);
}
return 0;
}
Enter first string: denis
Enter second string: balaguruswamy
The larger string is: balaguruswamy