Accordingly, you should keep just one conditionalized
file. To produce the different versions you want, you need only to retain or
eliminate the definition of VERBOSE
, as in the following example:
/* Define VERBOSE if you want two complete sentences. Do not define VERBOSE if you want two numbers only. */ #define VERBOSE #include/* Define the trade structure */ struct trade {double price; int number;}; /* Define auxiliary functions */ double mean_price (struct trade **array, int length) { int counter; double sum = 0.0; for (counter = 0; counter < length; ++counter) sum = sum + array[counter] -> price; return sum / counter; } double mean_size (struct trade **array, int length) { int counter; double sum = 0.0; for (counter = 0; counter < length; ++counter) sum = sum + array[counter] -> number; return sum / counter; } /* Define trade array */ struct trade *trade_pointers[100]; main ( ) { /* Declare various variables */ int limit, counter, number; double price; /* Read numbers from the file and stuff them into array */ for (limit = 0; 2 == scanf ("%lf%i", &price, &number); ++limit) { trade_pointers[limit] = (struct trade*) malloc (sizeof (struct trade)); trade_pointers[limit] -> price = price; trade_pointers[limit] -> number = number; } /* Perform analysis */ #ifdef VERBOSE printf ("The mean price per share of the trades is %.2f.\n", mean_price (trade_pointers, limit)); printf ("The mean number of shares traded is %.0f.\n", mean_size (trade_pointers, limit)); #else printf ("%.2f %.2f", mean_price (trade_pointers, limit), mean_size (trade_pointers, limit)); #endif }