博客专栏

EEPW首页 > 博客 > C语言字符篇(三)字符串比较函数

C语言字符篇(三)字符串比较函数

发布人:电子禅石 时间:2020-07-04 来源:工程师 发布文章
C语言字符篇(三)字符串比较函数    

            

            #include <string.h>    
int strcmp(const char *s1, const char *s2);    比较字符串s1和s2    
int strncmp(const char *s1, const char *s2, size_t n);    比较字符串s1和s2前n个字符    
 
如果两个字符一样大,返回值为 0
如果s1>s2,则返回正值,
如果s1<s2,则返回负值.
 
-------------------------------------------------------
int main(int argc, char **argv) 
{    const char *s1="hello";    
    const char *s2="hello";    
    const char *s3="aello";    
    int ret1,ret2;


    ret1=strncmp(s1,s2,strlen(s1));
    ret2=strncmp(s1,s3,strlen(s1));


    printf("%d\n",ret1);    //0
    printf("%d\n",ret2);    //7  return 0;
}


*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。



关键词:

相关推荐

技术专区

关闭