How to declare and compare the strings?
// test ="my test string";
char testDest[256];
char *p= _com_util::ConvertBSTRToString(URL->bstrVal);
strcpy(testDest, p);
How can I compare test with testDest?
How to declare and compare the strings?
// test ="my test string";
char testDest[256];
char *p= _com_util::ConvertBSTRToString(URL->bstrVal);
strcpy(testDest, p);
How can I compare test with testDest?
Use strcmp
. But I would suggest you go through a book on C programming first.
For non case sensitive comparisons try int strcmp ( const char * str1, const char * str2 )
http://www.cplusplus.com/reference/clibrary/cstring/strcmp/
If you want the string comparing to be case sensitive, i.e. "test" != "TEsT"
, use int memcmp ( const void * ptr1, const void * ptr2, size_t num )
.
http://www.cplusplus.com/reference/clibrary/cstring/memcmp/
So: typedef char string[]; string sz1 = "This is a test string." string sz2 = "This is a test string." string sz3 = "This Is A Test String." if(memcmp(sz1, sz2, strlen(sz1) > strlen(sz2) ? strlen(sz1) : strlen(sz2)) == 0) printf("sz1 and sz2 are equal"); else printf("sz1 and sz2 are not equal"); if(memcmp(sz1, sz3, strlen(sz1) > strlen(sz2) ? strlen(sz1) : strlen(sz2)) == 0) printf("sz1 and sz3 are equal"); else printf("sz1 and sz3 are not equal"); if(strcmp(sz2, sz3) == 0) printf("sz2 and sz3 are equal"); else printf("sz2 and sz3 are not equal");
EDIT: You can also use stricmp() for case sensitive comparisons.