Good morning!
I am attempting to do some C practice in preparation from an exam. In one of these prompts, the instructions are asking me to write an array that will be populated by random integers. This step was added onto the a previous step and are to be connected. In the previous step, I created an array with five values. There are two prototypes that were asked to be written and they are called from the main. The only issue that I am really having here that when I call the functions, they both have the same numbers. Why are the random integers being given to both sets of arrays?
Code:
#include <stdio.h>#include <stddef.h>
#include <stdlib.h>
void display(int testArray[]);
void randPop(int testArray[]);
int main()
{
int testArray [5] = {22, 3, 5, 707, 1};
randPop(testArray);
display(testArray);
return 0;
}
void display(int testArray[])
{
int i;
for (size_t i = 0; i < 5; ++i) {
printf("%7zu%13d\n", i, testArray[i]);
}
}
void randPop(int testArray[])
{
int j;
for (size_t j = 0; j < 5; ++j) {
testArray[j] = rand() % 100 + 1;
printf("%7zu%13d\n", j, testArray[j]);
}
}
Is there a way to supply randPop with random integers and leave display with the original specified integers when called from the same array? I want to pass testArray to both randPop and display.
Thank you for all help in advance! It is grealy appreciated!