// game_lags.c // // Written by YOUR-NAME (YOUR-ZID) // on TODAYS-DATE // // Builds a report of "lag spikes", which are the recorded frame lag durations // (in milliseconds) that are at or above a given acceptable threshold. #include #include // Provided function prototypes double average_lag(int lags[], int count); int worst_lag(int lags[], int count); // ----------------------------------------------------------------------------- int main(int argc, char *argv[]) { int num_lags = argc - 1; int goal; printf("Enter the maximum acceptable lag in milliseconds: "); scanf("%d", &goal); // TODO: Count how many of the recorded lags (in argv) are lag spikes, // i.e. durations that are >= goal. int num_spikes = 0; // TODO: replace NULL by malloc-ing an array big enough to hold exactly // num_spikes integers, then fill it in with just the lag durations that // are >= goal. int *spikes = NULL; // Output report printf("Number of lag spikes: %d\n", num_spikes); printf( "Average lag spike duration: %.2f ms\n", average_lag(spikes, num_spikes) ); printf("Worst lag spike duration: %d ms\n", worst_lag(spikes, num_spikes)); // TODO: free the array you malloc'd above. return 0; } // ----------------------------------------------------------------------------- // PROVIDED FUNCTIONS // ----------------------------------------------------------------------------- //////////////// DO NOT CHANGE ANY OF THE CODE BELOW HERE ////////////////////// // Returns the average of the values in lags, an array of count integers. double average_lag(int lags[], int count) { if (count == 0) { return 0; } double sum = 0; for (int i = 0; i < count; i++) { sum += lags[i]; } return sum / count; } // Returns the largest value in lags, an array of count integers. int worst_lag(int lags[], int count) { int worst = lags[0]; for (int i = 1; i < count; i++) { if (lags[i] > worst) { worst = lags[i]; } } return worst; }