Created
November 11, 2013 09:40
-
-
Save orymate/7410586 to your computer and use it in GitHub Desktop.
Crossplatform megoldás Windows alá és Curses-szel képernyő törlésére és puffereletlen beolvasásra getch-val. Fordítás Windowson a szokásos módon, ncurses esetén pl. `gcc -DUSE_CURSES foobar.c -lncurses`. Képernyő törlése: `clearscreen;`. Az int getch() függvény használatához a main függvény elején szerepeljen egy `init_getch;` parancs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef CLRSCR_H | |
#define CLRSCR_H | |
#include <stdio.h> | |
/* Curses használata esetén: */ | |
#ifdef USE_CURSES | |
#include <curses.h> | |
#include <stdlib.h> | |
void endwin2() | |
{ | |
endwin(); | |
} | |
#define putchar(C) printw("%c", C) | |
#define printf printw | |
#define clearscreen clear() | |
#define init_getch initscr();noecho();cbreak();refresh();atexit(endwin2); | |
#endif | |
#endif | |
/* Windows */ | |
#ifdef WIN32 | |
#include <windows.h> | |
int getch(); | |
#define clearscreen clrscr2() | |
// így kell, és kész. | |
void clrscr2() | |
{ | |
COORD coordScreen = { 0, 0 }; | |
DWORD cCharsWritten, dwConSize; | |
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); | |
CONSOLE_SCREEN_BUFFER_INFO csbi; | |
GetConsoleScreenBufferInfo(hCon, &csbi); | |
dwConSize = csbi.dwSize.X * csbi.dwSize.Y; | |
FillConsoleOutputCharacter(hCon, TEXT(' '), dwConSize, coordScreen, &cCharsWritten); | |
SetConsoleCursorPosition(hCon, coordScreen); | |
} | |
#endif | |
/* Szabványos félmegoldás */ | |
#ifndef clearscreen | |
#define clearscreen puts("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") | |
#endif | |
#ifndef init_getch | |
#define init_getch | |
#endif | |
#ifndef getch | |
#define getch getchar | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "clrscr.h" | |
#include <stdio.h> | |
int main() | |
{ | |
init_getch; | |
printf("Szia. Nyomj meg egy gombot."); | |
getch(); | |
clearscreen; | |
printf("Szia. Nyomj meg még egy gombot."); | |
getch(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment