#include<stdio.h> #include <string.h> int mystrcmp(char * p1,char * p2) { int ret=0; if(p1!=NULL||p2!=NULL) { while(*p1==*p2) { p1++; p2++; } if(*p1!=*p2) { ret=*p1-*p2; } } return ret; } int main() { char * p1="helloworld"; char * p2="hellowerld"; int ret=strcmp(p1,p2); int ret2=mystrcmp(p1,p2); if(ret==0||ret2==0) { printf("p1==p2\n"); } else if(ret>0||ret2>0) { printf("p1>p2\n"); } else if(ret<0||ret2<0) { printf("p1<p2\n"); } return 0; }
mystrcmp是自己实现的字符串比较函数
输出结果:
p1>p2
标签:p2,p1,int,ret,嵌入式,char,mystrcmp,C语言,strcmp From: https://www.cnblogs.com/zxtang/p/16852242.html