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
4 ответов
+ 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
+ 1
I ran your code with your inputs...and got "yes" as output.