//This program reads two strings and uses a function to determine whether or not
ID: 3831352 • Letter: #
Question
//This program reads two strings and uses a function to determine whether or not the two strings are the same if you ignore case it does not matter if a given character in the st
ring is uppercase or lowercase, the function ignoreCase returns a 1 if the strings are id
entacle, ignore case, and return zero otherwise. Write ignoreCase
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int ignoreCase(char *, char *);
int main( void ) {
char input1[1024], input2[1024];
printf("Enter a string : ");
scanf("%s", input1);
printf("Enter another string : ");
scanf("%s", input2);
if ( ignoreCase(input1, input2) )
printf("%s and %s are the same if you ignore case ", input1, input2);
else
printf("%s and %s are not the same, even when you ignore case ", input1, input2);
return 0;
}
Explanation / Answer
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int ignoreCase(char *, char *);
int main( void ) {
char input1[1024], input2[1024];
printf("Enter a string : ");
scanf("%s", input1);
printf("Enter another string : ");
scanf("%s", input2);
if ( ignoreCase(input1, input2) )
printf("%s and %s are the same if you ignore case ", input1, input2);
else
printf("%s and %s are not the same, even when you ignore case ", input1, input2);
return 0;
}
// method/function of ignoreCase
int ignoreCase(char *string1, char *string2) {
int i=0,j=0;
for(i=0; string1[i]!=''; i++)
{
}
for(j=0; string2[j]!=''; j++)
{
}
if(i!=j)
return 0;
else
{
{
for(i=0; string1[i]!=''; i++)
{
if( toupper(string1[i])!=toupper(string2[i]) )
return 0;
}
return 1;
}
}
}
//PLEASE MAKE SURE YOUR INPUT STRING DO NOT CONTAIN SPACEs
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.