Added 'C_C++/function_pointer_strategy.c'
This commit is contained in:
parent
d687006894
commit
128cf6500d
32
C_C++/function_pointer_strategy.c
Normal file
32
C_C++/function_pointer_strategy.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* @BAKE gcc $@ -o $*.out $(pkg-config --cflags --libs ncurses) && ./$*.out
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
signed main() {
|
||||
/* Irrelevant */
|
||||
initscr();
|
||||
cbreak();
|
||||
curs_set(0);
|
||||
noecho();
|
||||
nodelay(stdscr, true);
|
||||
scrollok(stdscr, true);
|
||||
/* ---------- */
|
||||
void recieve() {
|
||||
addstr("Recieved a message.\n");
|
||||
}
|
||||
void block() {
|
||||
addstr("A message was blocked.\n");
|
||||
}
|
||||
|
||||
void (*strategizing_function)(void) = recieve;
|
||||
|
||||
while (1) {
|
||||
char c = wgetch(stdscr);
|
||||
if (c != EOF) {
|
||||
strategizing_function = (strategizing_function == recieve ? block : recieve);
|
||||
}
|
||||
strategizing_function();
|
||||
napms(500);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user