程序员面试题精选---strcmp()函数的实现

http://blog.csdn.net/aclay/article/details/7560401
01.#include <iostream>   
02.#include <cstring>   
03.#include <cstdio>   
04.  
05.using namespace std;  
06.int strcmp_test(char *str1, char *str2) {  
07.    char *s1 = str1;  
08.    char *s2 = str2;  
09.    while(*s1 == *s2 && *s1 != '\0' && *s2 != '\0') {  
10.        s1++;  
11.        s2++;  
12.    }  
13.    if(*s1 == *s2) return 0;  
14.    else {  
15.        if(*s1 > *s2) return 1;  
16.        else return -1;  
17.    }  
18.}     
19.int main() {  
20.    char *str1 = "hello";  
21.    char *str2 = "hello";  
22.    int value;  
23.    value = strcmp_test(str1, str2);  
24.    cout << value << endl;  
25.    system("pause");  
26.    return 0;  
27.}  

你可能感兴趣的:(程序员面试题精选---strcmp()函数的实现)