Home Segments Index Top Previous Next

502: Mainline

You have learned about a program that presumes that trade data contain integers that encode industry types. Now suppose that you replace the industry-identifying digit by a string of characters that encodes all sorts of information about the trade.

The string itself has two parts, separated by a hyphen. The first part contains descriptive codes; the second part contains an abbreviated company name. The first character of the first part—F, T, C, M, H, or A—identifies the industry type:

*-- Industry code 
| 
|  *-- Company-identifying characters 
|  v 
v --- 
F-BLD    3.3  300 

If there are extra characters in the first part, and if one of those extra characters is X, the company has just paid a dividend. Similarly, if one of those extra characters is B, the company is under bankruptcy protection.

 *-- Dividend code 
 | 
 v 
AX-FLY   9.9  100 
  
 *-- Bankrupt-company code 
 | 
 v 
AB-CH11 10.1  100 

To read such descriptive strings, you must first create an input buffer—an array in which to store strings as they are read. You must be sure that the array that you create is long enough to hold all anticipated characters plus the required null character that serves as the end-of-string marker. For the information to be read by the analyze_trades program, 100 characters is far more than needed, but allocating an array of that size anticipates other uses for the array:

char input_buffer[100];