/*基本算法实现*/Linux中string.h里strcmp和strcpy函数的实现

string.h

extern int strcmp(const char*,const char*);

extern char* strcpy(char*,const char*);

string.c

int strcmp(const char *cs, const char *ct)

{

    unsigned char c1, c2;



    while (1) {

        c1 = *cs++;

        c2 = *ct++;

        if (c1 != c2)

            return c1 < c2 ? -1 : 1;

        if (!c1)

            break;

    }

    return 0;

}



char *strcpy(char *dest, const char *src)

{

    char *tmp = dest;



    while ((*dest++ = *src++) != '\0')

        /* nothing */;

    return tmp;

}

 

你可能感兴趣的:(String)