Sunday, March 9, 2014

How to Compare two CASE SENSITIVE TCHAR Strings are equal or not? if _tcscmp() not working fine

#include <windows.h>
#include <iostream>
#include "Shlwapi.h"
#include <tchar.h>
#include <conio.h>

using namespace std;
void main( void )
{
TCHAR *String1="This is my String";
TCHAR *String2="This iS my String";
int m_equality=0;
int ScanLineLength,EndLineLength;
ScanLineLength = _tcslen(String1);
EndLineLength=_tcslen(String2);
  if (ScanLineLength==EndLineLength)
  {
    for (int k=0;k<EndLineLength;k++)
    {
      if (String1[k]!=String2[k])
       {
  break;
  }
 else
 {
         m_equality++;
       }
     }
    if(m_equality==EndLineLength)
    {
      cout << "Both Strings are Equal";
    }
   else
    {
      cout << "Both Strings are not Equal";
    }
 }
  else
  cout << "Both Strings are not Equal";
getch();
}

OUTPUT:
Both Strings are not Equal

Note : if you use _tcscmp( ) or _tcsicmp( )  both are case insensitive comparers

No comments:

Post a Comment