问:实现两个字符串的比较
#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #include <assert.h> #include <string.h> int main() { char* p1 = "abcdefg"; char* p2 = "abcder"; int ret = strcmp(p1,p2); if (ret == 0) { printf("相等"); } else if (ret > 0) printf("arr1大"); else printf("arr2大"); return 0; }
#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #include <assert.h> #include <string.h> int my_strcmp(char* x, char* y) { assert(x && y); while (*x == *y) { if (*x == '\0') return 0;//相等 x++; y++; } return(*x - *y); } int main() { char* p1 = "abcdefg"; char* p2 = "abcder"; int ret = my_strcmp(p1, p2); if (ret == 0) { printf("相等"); } else if (ret > 0) printf("arr1大"); else printf("arr2大"); return 0; }
标签:return,int,代码,练习,ret,char,40,printf,include From: https://www.cnblogs.com/ayue6/p/17792157.html