How can i compare a character in C with other characters without using an 'if' with tons of '||'? For example let's say I have a character named 'i' that I want to compare with 8 other characters that have no connection between them whatsoever, and if 'i' equals to at least one of those 8 characters then the expression is true. Something like this:
if(i == c1 || i == c2 || i == c2 ........){ /* do stuff */}
But on a big application these comparisons are a lot, not just 3 or 8. Is there a smart and fast way to achieve something like this and not end up with ugly looking code? Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire