hi i have a very large array that i want to populate but i don want to run the for loops every time so i thought i would right a program to output text to fill the array and was wondering if this would work.
the array is int array[100][12][31];
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <time.h>
using namespace std;
#define getrandom( min, max ) ((rand() % (int)(((max) + 1) - (min))) + (min))
int main()
{
int temp, counter;
srand(time(NULL));
ofstream fout("MyFile.txt");
fout << "int array[100][12][31] =" << "\n" << "{";
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 12; j++)
{
for (int k = 0; k < 31; k++)
{
if ((counter % 15 == 0) && (counter != 0))
fout << "\n"; // after 15 numbers go to a new line in the file
temp = getrandom(1000, 9999); // used to get a number for the array
fout << temp << ", "; // seperate each element with a "," and a space
counter++;
}
}
}
fout << "};"; // ends the array with "};"
fout.close();
return 0;
}
i know this is kinda rough but i was hoping it would help, im not anywhere near being done with this program and i may need to increase the array by a factor of 100 before the end so im not sure how much time it will take to populate the array every time. i do realize that i will have to go back into the .txt to delete the last", " or the compiler will flag an error. if anyone has any ideas or sugestions it would be very much aperciated