#Write a C++ program that works exactly like strcnmp built-in function. It accepts two strings then it compares the two strings alphabetically considering number of characters to be compared, which is specified by the user. Define your function.
#include <iostream>
using namespace std;
void my_strcnmp(){
char s1[50], s2[50];
int i=0, c=0;
cout<<"Enter first string: ";
cin>>s1;
cout<<"Enter second string: ";
cin>>s2;
while(s1[i]!='\0' || s2[i]!='\0')
{
if(s1[i]!=s2[i])
{
c = 1;
break;
}
i++;
}
if(c==0)
cout<<"\nStrings are equal"<<endl;
else
cout<<"\nStrings are not equal"<<endl;
}
int main()
{
my_strcnmp();
return 0;
}
Comments
Leave a comment