From 0c248186141f1eb58cf107024160385afc7c1520 Mon Sep 17 00:00:00 2001 From: cigerxwinchaker Date: Tue, 12 Nov 2019 17:26:21 +0100 Subject: [PATCH] =?UTF-8?q?=C3=A4nderungen=20f=C3=BCr=20den=20memoryaccess?= =?UTF-8?q?=20key=20Cigerxwin=20Chaker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/main.cpp | 2 ++ src/SharedMemory.cpp | 10 +++++++--- src/SharedMemory.h | 2 ++ src/key.log | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 src/key.log diff --git a/main/main.cpp b/main/main.cpp index fdf836c..1bef42a 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -28,6 +28,8 @@ int main(int argc, char** argv) std::cout << "OUTPUT ------------------------ OUTPUT\n" << std::endl; //Memory that is used now //outprint of all memory + } else if (eingabe != "exit"){ + std::cout << eingabe << " <- is not a known command" << std::endl; } } return 0; diff --git a/src/SharedMemory.cpp b/src/SharedMemory.cpp index 77520f6..ff81723 100644 --- a/src/SharedMemory.cpp +++ b/src/SharedMemory.cpp @@ -1,14 +1,20 @@ #include #include "SharedMemory.h" #include +#include key_t changedKey() { + std::ofstream keyFile; + keyFile.open("key.log", std::ofstream::out | std::ofstream::trunc); + keyFile.clear(); int newKey; std::cout << "Type in a new Key for the Shared Memory Segment" << std::endl; std::cout << "new Key#"; std::cin >> newKey; std::cout <<"New Key is -> " << newKey << std::endl; + keyFile << newKey; + keyFile.close(); return key_t(newKey); } @@ -36,9 +42,7 @@ void initSharedMemory(void) { std::string answer = getAnswerFromUser(); if(answer.compare("y") == 0) { - std::cout << "Please type in a new Key:\n"; - std::cout << "#"; - std::cin >> impl.sharedMemoryKey; + impl.sharedMemoryKey = changedKey(); std::cout << "new Try with Key:c " << impl.sharedMemoryKey << std::endl; initSharedMemory(); } else if(answer.compare("n") == 0) { diff --git a/src/SharedMemory.h b/src/SharedMemory.h index 96aefca..344aacc 100644 --- a/src/SharedMemory.h +++ b/src/SharedMemory.h @@ -12,4 +12,6 @@ void deleteSharedMemory(int s); void deleteSharedMemory(void); void initSharedMemory(void); +key_t changedKey(); +std::string getAnswerFromUser(); #endif //SHARED_MEMORY_H diff --git a/src/key.log b/src/key.log new file mode 100644 index 0000000..bd41cba --- /dev/null +++ b/src/key.log @@ -0,0 +1 @@ +12345 \ No newline at end of file