OptimusMaximus OptimusMaximus - 1 year ago 63
C Question

Is there any way to write nested if conditions shorter?

Just instead of :

if ( ch == 'A' || ch == 'B' || ch == 'C' || .....

for example, to do it like :

if ( ch == 'A', 'B', 'C', ...

is there even a shorter way to summarize conditions ?

usr usr
Answer Source

strchr() can be used to see if the character is in a list.

const char* list = "ABCXZ";
if (strchr(list, ch)) {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download