From c26dc8415d238c65e90424a9b439a7d52ca5ffd0 Mon Sep 17 00:00:00 2001 From: Matti Date: Wed, 11 Dec 2024 23:36:38 +0100 Subject: [PATCH] Add Basic Reading --- ActualMain.cpp | 4 +++- Aufg9/DiabloByteReader.cpp | 36 ++++++++++++++++++++++++++++++++++++ Aufg9/DiabloByteReader.h | 11 +++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 Aufg9/DiabloByteReader.cpp create mode 100644 Aufg9/DiabloByteReader.h diff --git a/ActualMain.cpp b/ActualMain.cpp index 1c5d18f..c924a62 100644 --- a/ActualMain.cpp +++ b/ActualMain.cpp @@ -9,6 +9,7 @@ #include "Aufg6/MineSweeper.h" #include "Aufg7/SegFault.h" #include "Aufg8/SalesStatMain.h" +#include "Aufg9/DiabloByteReader.h" int main() { // Aufg1Main(); @@ -18,5 +19,6 @@ int main() { // Aufg5Main(); // Aufg6Main(); // Aufg7Main(); - Aufg8Main(); + // Aufg8Main(); + Aufg9Main(); } diff --git a/Aufg9/DiabloByteReader.cpp b/Aufg9/DiabloByteReader.cpp new file mode 100644 index 0000000..776f683 --- /dev/null +++ b/Aufg9/DiabloByteReader.cpp @@ -0,0 +1,36 @@ +#include +#include + +template +typ1 readFromStream(std::ifstream &stream, char *dest) { + if (stream.is_open()) { + stream.read(dest, sizeof(char[1024])); + typ1 *ptr = reinterpret_cast(dest); + return std::move(*ptr); + } + else { + std::runtime_error("Could not read from File!"); + } +} + +void Aufg9Main() { + char *dest = new char[1024]; + + try { + std::string fileName = "../Aufg9/IO-Files/charakter.d2s"; + std::ifstream stream(fileName); + auto header = readFromStream(stream, dest); + + printf("I read something!\n%X\n", header); + + for (int i = 0; i < 16; i++) { + std::cout << dest[i] << std::endl; + } + + long *test = reinterpret_cast(dest); + printf("Test: %X\n", *test); + + } catch (const std::exception &e) { + std::cout << e.what() << std::endl; + } +} diff --git a/Aufg9/DiabloByteReader.h b/Aufg9/DiabloByteReader.h new file mode 100644 index 0000000..31a67d0 --- /dev/null +++ b/Aufg9/DiabloByteReader.h @@ -0,0 +1,11 @@ +// +// Created by DH10MBO on 11.12.2024. +// + +#ifndef DIABLOBYTEREADER_H +#define DIABLOBYTEREADER_H + +void Aufg9Main(); + + +#endif //DIABLOBYTEREADER_H