Question 14: Compare two strings as strcmp() but in this program your comparison shouldn’t be case sensitive i.e. ‘A’ and ‘a’ should be considered same. If both strings are same, print “Same String” otherwise print “Different”.
Question 14: Compare two strings as strcmp() but in this program your comparison shouldn’t be case sensitive i.e. ‘A’ and ‘a’ should be considered same. If both strings are same, print “Same String” otherwise print “Different”.
/*
Name: Mudassar Ali
Roll: BCSF15M045 [Morning]
Assignment: No# 05
Teacher: Miss Sadia Shahzad
*/
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
cout<<"This programme will display the input strings are same or not without Case_Sensitivity!!\n\n";
char str1[20]; // To store the contents of first string.
char str2[20]; // To store the contents of second string.
bool flag = false; // For string compare.
cout<<"Enter First String:";
cin>>str1; // Inputting the first string.
cout<<"Enter Second String:";
cin>>str2; // Inputting the second string.
for(int i = 0; str1[i]!='\0'&&str2[i]!='\0';i++) // Loop for converting all upper case letters in both strings into small letters.
{
if(str1[i]>='A'&& str1[i]<='Z')
{
str1[i]+=32;
}
if(str2[i]>='A'&& str2[i]<='Z')
{
str2[i]+=32;
}
}
if(strcmp(str1,str2)==0) //comparing the both strings to check these are same or not.
{
flag = true;
}
if(flag) // if flag true the same string and vice versa.
{
cout<<"\nSame String!!";
}
else
cout<<"\nDifferent String";
return 0;
}
/*
Name: Mudassar Ali
Roll: BCSF15M045 [Morning]
Assignment: No# 05
Teacher: Miss Sadia Shahzad
*/
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
cout<<"This programme will display the input strings are same or not without Case_Sensitivity!!\n\n";
char str1[20]; // To store the contents of first string.
char str2[20]; // To store the contents of second string.
bool flag = false; // For string compare.
cout<<"Enter First String:";
cin>>str1; // Inputting the first string.
cout<<"Enter Second String:";
cin>>str2; // Inputting the second string.
for(int i = 0; str1[i]!='\0'&&str2[i]!='\0';i++) // Loop for converting all upper case letters in both strings into small letters.
{
if(str1[i]>='A'&& str1[i]<='Z')
{
str1[i]+=32;
}
if(str2[i]>='A'&& str2[i]<='Z')
{
str2[i]+=32;
}
}
if(strcmp(str1,str2)==0) //comparing the both strings to check these are same or not.
{
flag = true;
}
if(flag) // if flag true the same string and vice versa.
{
cout<<"\nSame String!!";
}
else
cout<<"\nDifferent String";
return 0;
}
No comments: