Memcmp and memicmp Functions

Source: Internet
Author: User

Function prototype: extern int memcmp (void * str1, void * str2, unsigned int N)

Parameter description: str1 and str2 are the specified strings to compare the first n Bytes of the two strings.

Database Name: # include <string. h>

Function: compare whether the first n Bytes of the string str1 and str2 in the memory area are the same.

Return Description: return value for str1 <str12 <0; return value for str11 = str12 = 0; return value for str11> str12> 0.

Other Instructions: none.

Instance:

# Include <string. h>
# Include <stdio. h>

Int main ()
...{
Char * str1 = "I'm sky2098, welcome to my website! ";
Char * str2 = "I'm sky2098, please do not call me sky2098! ";
Int inttemp;
Inttemp = memcmp (str1, str2, strlen ("I'm sky2098,"); // compare str1 and str2 in the memory zone before strlen ("I'm sky2098 ,") bytes are equal
If (inttemp = 0)
...{
Printf ("str1 and str2 has n Bytes which are the same as each other! /N ");
}
Return 0;
}

Compile and run in VC ++ 6.0:

Note that memcmp functions implement byte comparison rather than character comparison.

 

 

Function prototype: extern int memicmp (void * str1, void * str2, unsigned int count)

Parameter description: str1 and str2 are the specified strings for comparison, and the first count bytes of the two strings are compared, which is case-insensitive.

Database Name: # include <string. h>

Function: compare whether the first count bytes of the string str1 and str2 in the memory area are the same.

Return Description: return value for str1 <str12 <0; return value for str11 = str12 = 0; return value for str11> str12> 0.

Other Instructions: none.

Instance:

# Include <string. h>
# Include <stdio. h>

Int main ()
...{
Char * str1 = "I'm sky2098, welcome to my website! "; // The two strings have the same meaning, but are case-insensitive.
Char * str2 = "I'm sky2098, welcome to my website! ";
Int inttemp;
Inttemp = memicmp (str1, str2, strlen ("I'm sky2098, welcome to my website! "); // Compare str1 and str2 in the memory zone before strlen (" I'm sky2098, welcome to my website! ") Are the bytes equal?
If (inttemp = 0)
...{
Printf ("str1 and str2 has n Bytes which are the same as each other! ");
}
Return 0;
}

 

Compile and run in VC ++ 6.0:

The memicmp function is case-insensitive during comparison.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.