Copy Array

This is a warmup exercise. It is not compulsory, and may be completed individually or with your lab partner.

You should make sure you have completed showArray and scanArray before completing this task.

Copy your scanArray.c into a new file called copyArray.c like this:

cp scanArray.c copyArray.c

You will be implementing an array copying function, with the prototype void copyArray(int size, int fromArray[MAX_LENGTH], int toArray[MAX_LENGTH]), which should copy the values from the fromArray to the toArray.

You must also add these lines to the end of your main function, just before the return EXIT_SUCCESS:

int copiedArray[MAX_LENGTH];
copyArray(size, array, copiedArray);
showArray(size, copiedArray);

Some Examples

Enter array size: 3
Enter array values: 1 2 3
[1, 2, 3]
[1, 2, 3]
Enter array size: 1
Enter array values: 17
[17]
[17]

To run some simple automated tests:

$ 1511 autotest copyArray

To run Styl-o-matic:

$ 1511 stylomatic copyArray.c
Looks good!

You’ll get advice if you need to make changes to your code.

Submit your work with the give command, like so:

$ give cs1511 wk05_copyArray

Or, if you are working from home, upload the relevant file(s) to the wk05_copyArray activity on Give Online.