I am not sure why my coding is not the way it should work. For example, if I typ
ID: 3620786 • Letter: I
Question
I am not sure why my coding is not the way it should work.For example, if I type char like aBcD and abCD
the display should be aBcD and abCD are same. but I did not get it. Can anyone fix what I did wrong?
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int strcmpi(char [], char []);
int main()
{
char a[80], b[80];
printf("enter a string: ");
scanf("%s", a);
printf("enter a string: ");
scanf("%s", b);
int compare = strcmp(a,b);
if(compare ==0)
printf("%s and %s are the same ",a,b);
else if(compare<0)
printf("%s preceeds %s ",a,b);
else if(compare>0)
printf("%s preceeds %s ",b,a);
system("pause");
}
int strcmpi(char s[], char t[])
{
int i =0;
while (s[i] && (tolower(s[i])== tolower(t[i])))
i++;
return tolower(s[i])-tolower(t[i]);
}
Explanation / Answer
please rate - thanks would you believe you had strcmp instead of strcmpi! #include <stdio.h>#include <stdlib.h>
#include <ctype.h>
int strcmpi(char [], char []);
int main()
{
char a[80], b[80];
printf("enter a string: ");
scanf("%s", a);
printf("enter a string: ");
scanf("%s", b);
int compare = strcmpi(a,b);
if(compare ==0)
printf("%s and %s are the same ",a,b);
else if(compare<0)
printf("%s preceeds %s ",a,b);
else if(compare>0)
printf("%s preceeds %s ",b,a);
system("pause");
}
int strcmpi(char s[], char t[])
{
int i =0;
while (s[i] && (tolower(s[i])== tolower(t[i])))
i++;
return tolower(s[i])-tolower(t[i]);
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.