/*------------------------------------------------------------------------------------------------------------------------
Author: Sujith
Program: Write C++ programs to compare to string without using inbuilt functions
Prog Name: 1strcmp.cpp
Date: 21-04-2015
-------------------------------------------------------------------------------------------------------------------------*/
#include<iostream>
using namespace std;
int fnStrCmp(char s1[30],char s2[30]);
main()
{
int i;
char str1[30],str2[30];
system("clear");
cout<<"Program to comapre 2 strings\n";
cout<<"Enter first string\n";
cin>>str1;
cout<<"Enter second string\n";
cin>>str2;
i=fnStrCmp(str1,str2);
if(i==0){
cout<<"The 2 strings are equal\n";
}else{
cout<<"the 2 strings are not equal\n";
}
}
int fnStrCmp(char s1[30],char s2[30])
{
int a=0;
while(s1[a]==s2[a]){
if(s1[a]=='\0'){
return 0;
}
a++;
}
return 1;
}
OUTPUT:
"1strcmp.cpp" 33L, 729C written
[141740@localhost ~]$ g++ 1strcmp.cpp
[141740@localhost ~]$ ./a.out
Program to comapre 2 strings
Enter first string
EQUAL
Enter second string
EQUAL
The 2 strings are equal
[141740@localhost ~]$
[141740@localhost ~]$ g++ 1strcmp.cpp
[141740@localhost ~]$ ./a.out
Program to comapre 2 strings
Enter first string
MCA
Enter second string
MSC
the 2 strings are not equal
[141740@localhost ~]$
Author: Sujith
Program: Write C++ programs to compare to string without using inbuilt functions
Prog Name: 1strcmp.cpp
Date: 21-04-2015
-------------------------------------------------------------------------------------------------------------------------*/
#include<iostream>
using namespace std;
int fnStrCmp(char s1[30],char s2[30]);
main()
{
int i;
char str1[30],str2[30];
system("clear");
cout<<"Program to comapre 2 strings\n";
cout<<"Enter first string\n";
cin>>str1;
cout<<"Enter second string\n";
cin>>str2;
i=fnStrCmp(str1,str2);
if(i==0){
cout<<"The 2 strings are equal\n";
}else{
cout<<"the 2 strings are not equal\n";
}
}
int fnStrCmp(char s1[30],char s2[30])
{
int a=0;
while(s1[a]==s2[a]){
if(s1[a]=='\0'){
return 0;
}
a++;
}
return 1;
}
OUTPUT:
"1strcmp.cpp" 33L, 729C written
[141740@localhost ~]$ g++ 1strcmp.cpp
[141740@localhost ~]$ ./a.out
Program to comapre 2 strings
Enter first string
EQUAL
Enter second string
EQUAL
The 2 strings are equal
[141740@localhost ~]$
[141740@localhost ~]$ g++ 1strcmp.cpp
[141740@localhost ~]$ ./a.out
Program to comapre 2 strings
Enter first string
MCA
Enter second string
MSC
the 2 strings are not equal
[141740@localhost ~]$
No comments:
Post a Comment