// Bin2Asc - Convert binary files to ASCII
// By DreamVB 22:07 17/10/2016

#include <iostream>
#include <fstream>

using namespace std;
using std::cout;
using std::endl;

int main(int argc, char *argv[]){
	fstream fs;
	ofstream fo;
	int ch = 0;

	//Check file parms
	if (argc != 3){
		cout << "Converts a binary file to ASCII." << endl << endl;
		cout << "Usage: " << argv[0] << " <source><destination>" << endl;
		exit(1);
	}

	//Open input file
	fs.open(argv[1], ios::in | ios::binary);

	//Check if input file is opened.
	if (!fs){
		cout << "Input read error." << endl;
		exit(1);
	}

	//Open output file
	fo.open(argv[2],ios::out | ios::binary);

	//Check if output file was opened.
	if (!fo){
		cout << "Output file can not be created." << endl;
		fs.close();
		exit(1);
	}

	//Get and write bytes to file.
	ch = fs.get();
	while (!fs.eof()){
		//Write char value and line break to file.
		fo << (int)ch << "\n";
		//Get the next char
		ch = fs.get();
	}

	//Close output and input file.
	fo.close();
	fs.close();

	return 0;
}