Home Segments Index Top Previous Next

528: Mainline

Having redefined the industry-defining enumeration constants, you need only to replace the conditional part of the switch statement; the rest remains the same as it was:

char* industry_name (struct trade *t) { 
  switch (t -> description[0]) { 
    case food: return "Food"; break; 
      ... 
  } 
} 

Thus, enumeration constants provide a form of detail-hiding data abstraction, and, as usual with data abstraction, the use of enumeration constants simplifies change.