samedi 27 juin 2015

How to compare 2 char in C

Why this don't work? months[5] == name is equal. months[5] is Jun and name is Jun but if never execute...

 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;
    }

Aucun commentaire:

Enregistrer un commentaire