I am a beginner and trying to write a program for physics computations.
Currently the output being generated by a child program is sent to a separate text file and the parent program opens this file later and reads a value from it - the output is unnecessary to store, only the value is significant. It would be more elegant to use buffer for this purpuse, so that no extra text file would be generated in the process.
My question is how to get the output sent to buffer instead of file (micromegas.out below) and later search for the value in the buffer in the same manner as it is done for the output file in the code below?
string micromegas = "./micromegas_3.2/MSSM/main " + p[0] + " " + p[1] + " " + p[2] + " " + p[3] + " " + p[4] + " > micromegas.out";
// Execute child program and send output to micromegas.out
system(micromegas.c_str());
FILE *fout = fopen("micromegas.out", "r"); // open the output file and search for the value (Omega)
char * buffer =(char *)malloc(512);
long double Xf, calc_omega_hsq;
while(fgets(buffer, 512, fout))
{
if (sscanf(buffer, "Xf=%Lf Omega=%Lf", &Xf, &calc_omega_hsq)) {}
}
fclose (fout);
Output currently stored in file "micromegas.out" "==== Calculation of relic density ===== Xf=2.22e+01 Omega=1.34e+00"