I would like to make program that uses bubble sorting algorithm to sort some data from input program and write sorted values into output file - however everything seems fine, but the output file is empty...
I've tried to use a console as output but it didn't help. I know that there are functions for bubble sorting, but I'm quiet new in c++ topic and would like to gain some experience in it.
#include <iostream>
#include <fstream>
#include <string>
struct Datas
{
std::string day;
float value;
};
using namespace std;
int main ()
{
fstream file_in, file_out;
string name, line, data;
Datas current [7];
cout << "Input file name with data to open" << endl;
cin>>name;
file_in.open(name.c_str());
if (file_in.fail())
{
cout << "Unable to open file - try again" << endl;
// pause(TIME);
system ("CLS"); //Clears the console
main();
} else {
cout << "Input output file name to save sort datas" << endl;
cin>>name;
file_out.open(name.c_str());
if (file_out.fail())
{
cout << "Unable to open file - try again" << endl;
} else {
while (file_in.eof() == 0)
{
for (int pointer = 0; pointer < 7; pointer++)
{
file_in >> current[pointer].day >> current[pointer].value;
}
string tmp_day;
float tmp_val;
for (int current_val = 0; current_val < 7; current_val++)
{
if (current[current_val].value > current[current_val+1].value ||
current[current_val].value > current[current_val+2].value ||
current[current_val].value > current[current_val+3].value ||
current[current_val].value > current[current_val+4].value ||
current[current_val].value > current[current_val+5].value ||
current[current_val].value > current[current_val+6].value )
{
tmp_day = current[current_val+1].day;
tmp_val = current[current_val+1].value;
current[current_val].day = tmp_day;
current[current_val].value = tmp_val;
tmp_day = current[current_val].day;
tmp_val = current[current_val].value;
}
}
for (int stream = 0; stream < 7; stream++)
{
file_out << current[stream].day << '\t' << current[stream].value << endl;
}
}
file_in.close();
file_out.close();
return 0;
system("PAUSE"); //Keeps console window open after program execution
}
}
}