0

Finding whether given strings are of equal length

#include<stdio.h> #include<stdlib.h> #include<conio.h> #include<ctype.h> #include<string.h> int main() { Char s1[100],s2[100]; fgets(s1,100,stdin); fgets(s2,100,stdin); if(strlen(s1)==strlen(s2)) printf("yes"); else Printf("no"); Input India Nepal Output No Expected output yes Why am I getting incorrect output

11th Dec 2020, 9:45 AM
S.Brindha
S.Brindha  - avatar
2 odpowiedzi
+ 2
First of all, you used fgets() function .So it also takes gap as a input. So in your code ,when you give input: India Nepal in the Input India here it also take gap as a input so strlen(s1) returns 6 not 5. So it's better to use normal scanf in your code instead of fgets. here is the solution: https://code.sololearn.com/c3a13a2A23a1
11th Dec 2020, 10:02 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
I ran your code with your inputs...and got "yes" as output.
11th Dec 2020, 10:17 AM
rodwynnejones
rodwynnejones - avatar