From d986ff087909b55f9015801a6aa2544a59c0e6b4 Mon Sep 17 00:00:00 2001 From: Pablo Date: Wed, 18 Mar 2026 12:42:29 +0100 Subject: [PATCH] creacion del archivo getch con la funcion getch --- Practica1/getch.cpp | 19 +++++++++++++++++++ Practica1/main.cpp | 24 ++++-------------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Practica1/getch.cpp b/Practica1/getch.cpp index e69de29..6f1de0d 100644 --- a/Practica1/getch.cpp +++ b/Practica1/getch.cpp @@ -0,0 +1,19 @@ +#include +#include +#include + +using namespace std; + +char getch(void){ + struct termios oldt, newt; + char ch; + + tcgetattr(STDIN_FILENO, &oldt); + newt = oldt; + newt.c_lflag &= ~(ICANON | ECHO); + tcsetattr(STDIN_FILENO, TCSANOW, &newt); + ch = getchar(); + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); + + return ch; +}; diff --git a/Practica1/main.cpp b/Practica1/main.cpp index c8c5a02..d6ac50f 100644 --- a/Practica1/main.cpp +++ b/Practica1/main.cpp @@ -1,38 +1,22 @@ #include #include -#include -#include -#include + using namespace std; -char getch(void){ - struct termios oldt, newt; - char ch; - - tcgetattr(STDIN_FILENO, &oldt); - newt = oldt; - newt.c_lflag &= ~(ICANON | ECHO); - tcsetattr(STDIN_FILENO, TCSANOW, &newt); - ch = getchar(); - tcsetattr(STDIN_FILENO, TCSANOW, &oldt); - - return ch; -} - void clear(){ - ifstream archivo("/etc/os-release"); + ifstream archivo("/etc/os-release"); if (archivo.good()) { system("clear"); } else { system("cls"); } - }; +}; int main() -{ + char opcion=0; while (opcion!='8') {