mercredi 23 novembre 2016

Char comparison on if statement doesn't evaluate to true

Why doesn't the following IF statement evaluate to true, even though sex[i] has the value of M char?

for (i=0;i<3;i++)
if (sex[i] == 'M' || sex[i] == 'm')

What i'm trying to do, is create an array of characters that holds several values for strings or characters. In this case, it's a character and it works outside the if function, if i print sex[0] i get M.

Oh, and i know that the variable needs to be declared like this

char sex[size][sizeofstring]

Aucun commentaire:

Enregistrer un commentaire