Answer to Question #215853 in C++ for Fuad Endris

Question #215853

#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.



1
Expert's answer
2021-07-11T14:35:52-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS