Hi to all.
Hereunder there is the code of a program that simply generates ascii codes for 0-9 and A-Z for serial numbers. for example it generates a line like this:
ABCDE-FGHIJ-KLMN0-12345-67899
I want to have 50,000 serial numbers to be generated and all saved to a single file output.txt
I first made the code and it only saved one thus the last one than i edited my code (as shown below) so that it opens the file and adds to a new line so that all serials are saved but it is not working. Can you please help me out with this procedure.
The code is as follows:
Thanks & Regards
Combinu
Hereunder there is the code of a program that simply generates ascii codes for 0-9 and A-Z for serial numbers. for example it generates a line like this:
ABCDE-FGHIJ-KLMN0-12345-67899
I want to have 50,000 serial numbers to be generated and all saved to a single file output.txt
I first made the code and it only saved one thus the last one than i edited my code (as shown below) so that it opens the file and adds to a new line so that all serials are saved but it is not working. Can you please help me out with this procedure.
The code is as follows:
Code:
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <fstream>
void saveArray (char* array, int length);
int main (int argc, const char * argv[])
{
int n, l, ln;
int ascii[25] = {0};
char serial[25] = {0};
srand((unsigned)time(0));
for(int z=0; z<50000; z++)
{
for (int i =0; i < 25; i++)
{
ln = (rand()%2);
if (ln == 0)
{
n = (rand()%10)+48;
ascii[i] = n;
}
else if (ln == 1)
{
l = (rand()%26)+65;
ascii[i] = l;
}
serial[i] = static_cast<char>(ascii[i]);
}
saveArray(serial, 25);
}
}
void saveArray (char* array, int length)
{
std::fstream filestr;
std::ofstream output ("/users/manuelportelli/Documents/C++ Projects/Serial_Generator/Serial_Generator/ouput.txt");
for (int j=0; j<length; j++)
{
//for (int k=0; k<5; k++)
// {
filestr.open ("/users/manuelportelli/Documents/C++ Projects/Serial_Generator/Serial_Generator/ouput.txt", std::fstream::in | std::fstream::out | std::fstream::app);
filestr<<array[j]<<std::endl;
//}
}
}
Thanks & Regards
Combinu