如何比较C中的2个字符

How to compare 2 char in C

为什么这不起作用? months[5] == name 是相等的。 months[5]Jun 并且 nameJunif 永远不会执行...

 int getMonthNum(char * name){
    char *months[12] ={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
    char *pointertoarray = &months;
    int i;
        for(i = 1; i <= 12; i++){
            if(months[5] == name){
                return i;
            }
        }
    return i;
    }

使用 strcmp 否则它会比较指针。

int getMonthNum(char * name){
    char *months[12] ={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
//char *pointertoarray = &months;
    int i;
        for(i = 0; i < 12; i++){
            if( strcmp(months[i], name)==0){
                return i;
            }   
        }   
    return i;
    }   

http://www.tutorialspoint.com/c_standard_library/c_function_strcmp.htm