c代码-C语言编写一个程序,比较字符数组str2和字符数组str3的大小,并且str2与str1的数组成员不相等,不能使用string.h头文件
时间: 2024-05-31 17:07:19 浏览: 93
#include <stdio.h>
int main() {
char str1[] = "hello";
char str2[] = "world";
char str3[] = "hello";
int i = 0;
while (str2[i] != '\0' && str3[i] != '\0') {
if (str2[i] != str3[i]) {
break;
}
i++;
}
if (str2[i] == '\0' && str3[i] == '\0') {
printf("str2 and str3 are equal\n");
}
else if (str2[i] < str3[i]) {
printf("str2 is smaller than str3\n");
}
else {
printf("str2 is larger than str3\n");
}
i = 0;
while (str2[i] != '\0' && str1[i] != '\0') {
if (str2[i] == str1[i]) {
printf("str2 and str1 have the same member at index %d\n", i);
return 0;
}
i++;
}
printf("str2 and str1 do not have the same member\n");
return 0;
}
阅读全文