Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

What is memicmp() Function in C++

The word "memicmp" is stands for memory ignore compare. This Function is similar to memcmp() function but here the comparison is not case sensitive. Its mean that memicmp() function ignores the character case (lower or upper). It is also used to compare specified number of bytes (or characters) of two strings stored in two memory blocks.

Syntax of memicmp() Function

In C++, the general syntax of this function is as follows:
var = memcmp (ptr1, ptr2, num);

Where:
var It represents integer variable that is used to store output returned by function.
ptr1 It indicates pointer to first block of memory.
ptr2 It indicates pointer to second block of memory.
num It represents number of bytes to compare.
The memicmp() function returns output in the following ways:
  • If first string is equal to the second string, then it will return 0.
  • If first string is less than second string, then it will return less than 0.
  • If first string is greater than second string, then it will return greater than 0.

Example of memicmp() Function

The following source code of C++ program compare two strings.

#include

#include

main()

 {

   char *s1 = "abcd";

   char *s2 = "ABCD";

   char *s3 = "wxyz";

   int num;

   num = memcmp (s1, s2, 3);



   if (num == 0)

          cout
   num = memcmp (s2, s3, 3);

   if (num > 0)

          cout
   else

          cout
return 0;

}


The memcmp() and memicmp() both functions are similar, the main difference is that memcmp() function is case sensitive (keep difference between lower and upper case letters). Whereas the memicmp() function doesn't keep difference between lower and upper case letters.


This post first appeared on Programming Explain, please read the originial post: here

Share the post

What is memicmp() Function in C++

×

Subscribe to Programming Explain

Get updates delivered right to your inbox!

Thank you for your subscription

×