Compare Length of Two different strings using UDF in C Language.
#include<stdio.h>
int compLength(char s1[], char s2[])
{
int l1,l2;
for(l1=0;s1[l1]!='\0';l1++); //length of string1
for(l2=0;s2[l2]!='\0';l2++); //length of string2
if(l1==l2) return 1;
else return 0;
}
int main()
{
char str1[100], str2[100];
int x;
printf("\nEnter 1st String: ");
gets(str1);
printf("\nEnter 2nd String: ");
gets(str2);
x=compLength(str1,str2);
if(x) printf("Both strings length is same.\n");
else printf("Both strings length is not same.\n");
}
No comments
Post your comments