Page 1
of 2
#include<ctype.h> #include<iostream>
#include<string.h> using namespace std;
void
convertToUppercase (char *);
main() {
|
|
char
firstString[50];
char
secondString[50];
char
uppercaseFirstString[50];
char
uppercaseSecondString[50];
char
concatString[100];
cout<<"Enter
String 1 : ";
cin>>firstString;
cout<<"Enter
String 2 : ";
cin>>secondString;
cout<<"\n\n";
cout<<"The
Length Of String 1 is : "<<strlen(firstString);
cout<<"\n";
cout<<"The
Length Of String 2 is : "<<strlen(secondString);
strcpy(uppercaseFirstString,firstString );
strcpy(uppercaseSecondString,secondString);
convertToUppercase(uppercaseFirstString);
convertToUppercase(uppercaseSecondString);
cout<<"\n\n";
cout<<"String
1 in upper case : "<<uppercaseFirstString<<"\n";
cout<<"String
2 in upper case : "<<uppercaseSecondString<<"\n";
cout<<"\n\n";
if(strcmp(uppercaseFirstString,uppercaseSecondString)==0)
{
cout<<"Both
strings are the same \n";
}
else {
cout<<"Both
strings are different \n";
Page 2
of 2
strcpy(concatString,firstString);
strcat(concatString,secondString); cout<<"\n\n";
cout<<"Both
Strings after Concatenation : " <<concatString;
return 0;
}
void
convertToUppercase (char *sptr)
{
while ( *sptr !=
'\0' )
{
if
(islower(*sptr) )
*sptr = toupper ( *sptr );
++ sptr;
}
}
No comments:
Post a Comment