Home Segments Index Top Previous Next

524: Mainline

Before you go on, recall that switch views characters as a type of integer. Accordingly, you can use a particular character in a character array in place of an integer:

char* industry_name (struct trade *t) { 
  switch (t -> description[0]) { 
    ... 
  } 
} 

As long as you compare the first character in the description character array—the one encoding the industry type—with various characters, viewed as integers, switch works just fine.