// count_steps.c // // Written by YOUR-NAME (YOUR-ZID) // on TODAYS-DATE // // Counts out a dance routine, phrase by phrase, into a single array. #include #include #include // Constants #define MAX_PHRASES 100 // Function prototypes int *count_steps(int phrases[MAX_PHRASES], int num_phrases); // ----------------------------------------------------------------------------- //////////////// DO NOT CHANGE THE MAIN FUNCTION /////////////////////////////// int main(void) { int phrases[MAX_PHRASES]; int num_phrases = 0; int length; printf("Enter the phrase lengths:\n"); while (num_phrases < MAX_PHRASES && scanf("%d", &length) == 1) { phrases[num_phrases] = length; num_phrases++; } if (num_phrases == 0) { printf("No steps to count!\n"); return 0; } int *count = count_steps(phrases, num_phrases); // Work out how many steps were counted out in total. int total = 0; for (int i = 0; i < num_phrases; i++) { total += phrases[i]; } printf("Count:"); for (int i = 0; i < total; i++) { // If you're getting an error here, // you have returned an array that is too small printf(" %d", count[i]); } printf("\n"); free(count); return 0; } // ----------------------------------------------------------------------------- // YOUR FUNCTIONS // ----------------------------------------------------------------------------- // Return a newly allocated array holding the full count for the routine: // the numbers 1 up to each phrase's length, for every phrase in order. int *count_steps(int phrases[MAX_PHRASES], int num_phrases) { // TODO: Complete this function return NULL; }