labs-edaf30/lab1/decode.cc

34 lines
822 B
C++
Raw Normal View History

2024-11-12 12:53:50 +01:00
#include <iostream>
#include <fstream>
#include "coding.h"
int main(int argc, char* argv[]) {
std::string filename;
if (argc > 1) {
filename = argv[1];
} else {
std::cout << "Enter filename to decode: ";
std::cin >> filename;
}
std::ifstream infile(filename, std::ios::binary);
if (!infile) {
std::cerr << "Could not open file " << filename << "\n";
return 1;
}
std::ofstream outfile(filename + ".dec", std::ios::binary);
if (!outfile) {
std::cerr << "Could not create output file" << "\n";
return 1;
}
unsigned char c;
while (infile.get(reinterpret_cast<char&>(c))) {
outfile.put(decode(c));
}
std::cout << "Decoding complete. Output saved to " << filename << ".dec" << "\n";
return 0;
}