Oberyn Martell Oberyn Martell - 1 month ago 6
C++ Question

What data file is suitable for my C++ code

For my C++ project, I need to make statistics and write code output in some txt file.

void txt()
{
FILE *fid0;
fopen_s(&fid0, "Agenti_20.txt", "w+");
for (int k = 0; k < numberofRepeat; k++)
{
for (int i = 0; i < numberofCalc; i++) {
fprintf(fid0, "%lf\n ", FunkcijaGreske[i]);

}
}
fclose(fid0);


}

numberofRepeat equals 100, numberofCalc is 20000, and FunkcijaGreske[i] is a double number.
So, right now, my code creates one .txt file with one column and 2000000 rows and its not suitable for manipulating with it.
I intend to have different columns for every repetition of my code, to have 100 repeat columns with 20000 calc rows and I'm not sure how to achieve that.
However, is .txt file suitable for writing a lot of data like in this case or should I use different kind of data file for future projects?
Every help appreciated.

Answer Source

Why not flip the order to write it row by row? Also text should be OK for what you're doing.

void txt() {
   FILE *fid0;
   fopen_s(&fid0, "Agenti_20.txt", "w+");
   for (int i = 0; i < numberofCalc; i++) {
       for (int k = 0; k < numberofRepeat; k++)
           fprintf(fid0, "%lf ", FunkcijaGreske[i]); 
       fprintf(fid0, "\n"); 
   }
   fclose(fid0);
}