Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   how to use strncmp function to compare two string input by user in C++ (http://www.go4expert.com/forums/strncmp-function-compare-string-input-t17853/)

san gabriel 4Jun2009 05:42

how to use strncmp function to compare two string input by user in C++
 
Code:

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
        char s1 = "";
        char s2 = "";
        cout << "Input String1: " ;
        cin >> *s1;
        cout << "Input String2: " ;
        cin >> *s2;
       
        if ( strcmp( s1, s2 ) > 0 )
                cout << "\nThe first string is greater than the second  string." << endl;
        else if ( strcmp( s1, s2 ) == 0 )
                cout << "\nThe first string is equal to the second string." << endl;
        else if ( strcmp( s1, s2 ) < 0 )
                cout << "\nThe first string is less than the second string." <<endl;
        return 0;
}


xpi0t0s 4Jun2009 22:11

Re: how to use strncmp function to compare two string input by user in C++
 
> char s1 = "";
> cin >> *s1;

I doubt this will compile.


All times are GMT +5.5. The time now is 15:57.