string

write a program that uses a function strcmp to compare two strings inputs by the user.the program should state whether the first string is less than ,equal to or greater than the second string.

Last edited on
closed account (28poGNh0)
what question?
write a program that uses a function strcmp to compare two strings inputs by the user.the program should state whether the first string is less than second string ,equal to second string or greater than the second string.
closed account (28poGNh0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# include <iostream>
# include <cstring>
# include <cstdio>
using namespace std;

int main ()
{
    // Considiring a less than b
    
    char firstStr[30],secondStr[30];
    cout << "Enter the first string -> ";gets(firstStr);
    cout << "Enter the second string -> ";gets(secondStr);

    if(!strcmp(firstStr,secondStr))
    {
        cout << "The two strings are equal" << endl;
    }else if(strcmp(firstStr,secondStr)>0)
    {
        cout << "The first string is greather than the second string" << endl;
    }else cout << "The first string is less that the second string" << endl;

    return 0;
}


hope that helps
many thank you @techno01
Techno01 did mean that we did saw your homework description, but we saw no questions originating from you. We saw no code that you have written yourself, and thus saw no bits in it that you have difficulty with.

The purpose of exercises is that you learn, and you do learn best by doing. When you have done some, and have a concrete code problem, then we can help.
closed account (28poGNh0)
@keskiverto I agree with that tottaly and I feel shame contrubiting on such thing .I hope that he learn from this code and try to miss with it ,otherwise no good will come from it

thanks again for clearifying this point
Topic archived. No new replies allowed.