码迷,mamicode.com
首页 > 其他好文 > 详细

关于strcmp()的实现

时间:2015-09-25 16:34:18      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:c语言strcmp()实现代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cmp(char *p1,char *p2);

int main()
{
    char s1[20],s2[20];
    int re;
    gets(s1);
    gets(s2);
    re=cmp(s1,s2);
    printf("%d\n",re);

    return 0;
}

int cmp(char *p1,char *p2)
{
    while(*p1==*p2)                 //如果有相同的字符,则要进行下一个字符比较;
    {
        if(*p1==‘\0‘)              //由于*p1==*p2,这条语句是判定*p1与*p2所指字符是不是\0,也就是结束符;
            return 0;
        p1++;
        p2++;

    }
    return (*p1-*p2);
}


本文出自 “阳子” 博客,转载请与作者联系!

关于strcmp()的实现

标签:c语言strcmp()实现代码

原文地址:http://9832751.blog.51cto.com/9822751/1698239

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!