Home Segments Index Top Previous Next

420: Mainline

As it stands, the switch statement in the analyze_trades program displays a message when it encounters an unknown industry code. You may choose to have the program take more drastic action, however, such as terminating whenever it encounters an unknown industry code. To arrange for an orderly termination, you need to inform the C compiler that you intend to make use of the exit function by including the following line in your program:

#include   

Then, you can insert a call to the exit function after the warning is displayed:

switch (industry) { 
  case 1: case 5: 
  ... 
  case 0: case 2: case 3: case 4: break; 
  default: printf ("Industry code %i is unknown!\n", industry); 
           exit (0); 
} 

Note that exit expects an integer argument. That integer argument generally should be 0, thereby indicating that your program's termination is not to evoke a special reaction from your operating system.