Home Segments Index Top Previous Next

429: Mainline

At this point, you have seen a switch statement that analyzes integer industry codes and creates appropriate trade objects:

switch (industry) { 
  case 1: case 5: 
    trade_pointers[limit]  
      = (struct trade*) malloc (sizeof (struct trade)); 
    trade_pointers[limit] -> price = price; 
    trade_pointers[limit] -> number = number; 
    ++limit; 
    break; 
  case 0: case 2: case 3: case 4: break; 
  default: printf ("Industry code %i is unknown!\n", industry); 
           exit (0); 
} 

Although this switch statement works fine, it is difficult to remember which number goes with which industry. In general, it is difficult to maintain a program that is littered with such nonmnemonic encoding.