1. 程式人生 > >實現strcmp函式

實現strcmp函式

int mystrcmp(const char* str1,const char* str2)
{
    int temp=0;
    while(!(temp=*(unsigned char*)str1-*(unsigned char*)str2)&&*str1)
    {
        str1++;
        str2++;
    }
    if(temp>0) temp=1;
    else if(temp<0) temp=-1
    return temp;
}