黑马程序员技术交流社区
标题: 自己写的一个代码判断字符串是否相等 [打印本页]
作者: wulei1982516 时间: 2015-9-10 21:39
标题: 自己写的一个代码判断字符串是否相等
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[]) {
char *color1="white";
char *color2="white";
if (strlen(color1)==strlen(color2)) {
for (int i=0; i<strlen(color2); i++) {
int a=*(color1+i);
int b=*(color2+i);
if (a!=b) {
printf("不相同");
return 0;
}
}
printf("相同");
}else{
printf("不相同");
}
return 0;
}
作者: coding_wang 时间: 2015-9-11 01:00
虽然我知道你想练代码, 但是看你用了 strlen 然后又不用strcmp 我的强迫症就范了~~~哈哈
作者: 羊口羊口羊 时间: 2015-9-11 01:10
秒懂,今天刚好复习到这一块!
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) |
黑马程序员IT技术论坛 X3.2 |