string compare
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <stdio.h> #include <stdlib.h> int String_Compare (const char* _First_String_, const char* _Second_String_); int main (void) { char* _String[2] = { _String[0] = "apple", _String[1] = "apple"}; printf ("%d\n", strcmp (_String[0], _String[1])); printf ("%d\n", String_Compare (_String[0], _String[1])); return 0; } int String_Compare (const char* _First_String_, const char* _Second_String_) { int result = 0; while (!(result = *(unsigned char*) _First_String_ - *(unsigned char*) _Second_String_) && *_Second_String_) ++_First_String_, ++_Second_String_; if (result < 0) return -1; else if (result > 0) return 1; return 0; } | cs |
0 개의 댓글:
댓글 쓰기