now that im awake i will try to explain this some more lol!
#include "stdafx.h"
#include <cstdlib>
#define length(a) (sizeof a / sizeof a[0])
i've included the cstdlib to gain access to rand and RAND_MAX so i can generate some random numbers.
Also note the define, i have created this define to find the length of an array, since the sizeof returns the byte size of something and not the actual number of elements i need to get the actual byte size of an int and the the array and divide em out to get the total number of elements (or so i believe that is what is going on lol)
void ArrayGenerator(int * MyArray, int ArraySize) {
int lowest = 1,
highest = 50,
range = (highest - lowest) + 1;
the lines lowest, highest, and range are used to generate random numbers within a certain area, i just happened to want numbers between 1 and 50, you could very easily modify the function to require arguments specifiying the range
//act like we are generating random numbers
for(int i = 0; i < ArraySize ; i++)
{
*(MyArray + i) = lowest + int(range * rand() / (RAND_MAX + 1.0));
}
}
these lines are pretty simple, while im less than the array enter a random number into the array at the pointed too position
*(MyArray + i) states to go to the location pointed at plus whatever 'i' is.
int _tmain(int argc, _TCHAR* argv[])
{
int FillThisArray[10];
int * fillArray = FillThisArray;
ArrayGenerator( fillArray, length(FillThisArray) );
return 0;
}
first i initialize an array 10 in size, then i create an int pointer (*) to the array fillArray.
i call the fuction and pass it my pointer to the array and call the defined macro length to get the size of the array.
all is well that ends well right