I am trying to write code to check whether two C-string variables are the same barring the difference of capitalization. Given the two input books BOOKS, the program should return 1, and with Incorrect correct, it should return 0. My code doesn't print it accurately.
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
int Judge_Char(const char* str1,const char* str2){
char first[20],second[20];
for(int i=0;i<20;i++){
first[i]=str1[i];
second[i]=str2[i]; //assigned pointers to variable
} //bc I didn't know other ways to compare
int k=0,l=0;
for(k=0;first[k]!='\0';k++);
for(l=0;second[l]!='\0';l++); //got the length of the chars here
for(int i=0;i<k;i++){
first[i]=toupper(first[i]);
} //i converted them to same case here
for(int i=0;i<l;i++){
second[i]=toupper(second[i]);
}
for(int n=0;n<k;n++){
for(int m=0;m<l;m++){
if(first[n]==second[m]){
return 1; // i check whether they are same or not
}
else{
return 0;
}
}
}
}
int main()
{
char a[20],b[20];
cin>>a>>b;
int flag=Judge_Char(a,b);
cout<<flag<<endl;
return 0;
}
CStringis an unrelated C++ class. learn.microsoft.com/en-us/cpp/atl-mfc-shared/…