Reading files, Output files

if my Files are ordered from file-000.txt to file-100.mca
My files path is “/home/Baja/Downloads/file-000.mca, …”
How can modify the attached code to read the files one by one, and also save the output results.
and how can i make the output files.txt with the same name, and automatic saves in a folder !
for example if the input file is “/home/Baja/Downloads/InputFolder/file-000.mca, …”, the output will be " “/home/Baja/Downloads/ResultsFolder/file-000.txt …”

BAJA.C (367 Bytes)

Something like that:

   ofstream outputfile;"Results.txt");
   ifstream inputfile;"file-001.mca");

   double E2=0, C2=0, E1=0, C1=0;
   for (int i = 0; i <=100, i++) {"file-00%d.mca",i));
      while (inputfile >> E1 >> C1){
         if (E1==E2){
            C2 = C2+C1;
         } else {
            outputfile << E2 << "        " << C2 << endl;
            E2 = E1;
            C2 = C1;
   outputfile << E2 << "        " << C1 << endl;

Its OK,
It will work from file-000 to file-009, but from file-010 to file-100 !
can i save the output results files with the same sequences (Results-000.txt to Results-100.txt) ?"file-%3.3d.txt",i));
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.