A pitfall in the use of strcmp Functions

Source: Internet
Author: User
According to Baidu Encyclopedia: http://baike.baidu.com/view/1026924.htm?introduction

Prototype: extern int strcmp (const char * S1, const char * S2 );

Header file: String. h

Function: Compares S1 and S2 strings.

General Format: strcmp (string 1, string 2)

Note:

When S1 <S2, the return value is-1.

When S1 = S2, the return value is 0.

When S1> S2, the return value is 1.

Note: C ++ Medium

When S1 <S2, the return value is less than 0.

When S1 = S2, the return value is equal to 0.

When S1> S2, the return value is greater than 0.

 

Note that this function returns 1 or-1 in C and is less than 0 or greater than 0 in C ++. It is not set to 1 or-1.

An error occurs if the comparison is performed based on the C interface and 1 and-1.Remember

To be compatible with C, it is best to use a value greater than 0 and less than 0, instead of comparing it with 1-1.

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.