In my code I did this
int y=strcmp(s,s1);//before this I converted all the uppercase of the string input as lower case.
if(y==0)
{
cout<<"0"<<endl;
}
else if(y >= 1)
{
cout<<"1"<<endl;
}
else if(y<1)
{
cout<<"-1"<<endl;//problem was here
}
so i took aaaa
and aaaA
as input and expected 0
as output. But it gave me -1
as output. But in my code when I wrote this:
int y=strcmp(s,s1);
if(y==0)
{
cout<<0<<endl;
}
else if(y >= 1)
{
cout<<1<<endl;
}
else if(y<1)
{
cout<<-1<<endl;
}
It gave me the right answer. My question why this happened?
you removed " " in the cout. Can you show the error code you're getting in the first round?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.