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

san gabriel's Avatar, Join Date: Jun 2009
Newbie Member
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;
}

Last edited by shabbir; 4Jun2009 at 08:46.. Reason: Code blocks
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
> char s1 = "";
> cin >> *s1;

I doubt this will compile.