回复 9# carazy 的帖子
你写的不行吧。。
#include <stdio.h> #define STRINGLEN 81 struct string { int len; char ch[STRINGLEN]; }; typedef struct string STRING; //串比较 int StrCompare(s, t) STRING *s, *t; { int i = 0; while ((s->ch[i] = t->ch[i]) && (s->ch[i] != '\0') && (t->ch[i] != '\0')) i++; return s->ch[i] - t->ch[i]; } //我的实现: typedef struct string *my_string_t; int new_str_cmp(const my_string_t lv, const my_string_t rv) { int i; if (lv->len != rv->len) return 0; for (i = 0; i < lv->len; i++) { if (lv->ch[i] != rv->ch[i]) return 0; } return 1; } //#define StrCompare new_str_cmp int main() { STRING s[3] = {{5, "Hello"}, {5, "Hello"}, {7, "HelloWd"}}; printf("%d,%d,%d\n", StrCompare(s, s + 1), StrCompare(s + 1, s + 2), StrCompare(s, s + 2)); return 0; }