commit 39c9777455951e0f3e13ced2e86d846800c9358c Author: Sergio Valor Martínez Date: Thu Apr 20 16:16:13 2023 +0200 Imprime el fichero binario por pantalla diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b139a18 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +.vscode +*.DS_Store +thumbs.db +*.exe +*_macos +*_linux +*.dmg +*.tar.gz +*.zip +*.app +*_debug* +main \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..22dacbb --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +all: + clang++ main.cpp -std=c++11 -Wall -Os -ffunction-sections -fdata-sections -o main \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..7759445 --- /dev/null +++ b/main.cpp @@ -0,0 +1,58 @@ +#include +#include +#include // std::cout +#include // ifstream, ofstream +#include // basename() +#include + +using namespace std; + +ifstream inputFile; +string filePath = ""; +vector buffer; + +void checkParameters(int argc, char *argv[]) +{ + if (argc != 2) + { + cout << "Uso: " << basename(argv[0]) << " FILE" << endl; + exit(EXIT_FAILURE); + } + else + filePath = argv[1]; +} + +void loadFile(string s) +{ + inputFile.open(s, ios::binary); + if (!inputFile.good()) + { + cout << "No se puede abrir el archivo: " << s << endl; + exit(EXIT_FAILURE); + } + + // Copia el stream al buffer + vector temp(std::istreambuf_iterator(inputFile), {}); + buffer = temp; +} + +void printBuffer() +{ + int count = 0; + for (auto i : buffer) + { + cout << static_cast(i) << " "; + count++; + if (count % 16 == 0) + cout << static_cast(i) << endl; + } +} + +int main(int argc, char *argv[]) +{ + checkParameters(argc, argv); + loadFile(filePath); + printBuffer(); + cout << "Fin del programa" << endl; + return 0; +}