Thread View: be.comp.programming
3 messages
3 total messages
Started by Gunter Schelfhout
Sat, 05 Oct 2002 13:34
Uit lus breken via keypress
Author: Gunter Schelfhout
Date: Sat, 05 Oct 2002 13:34
Date: Sat, 05 Oct 2002 13:34
15 lines
1349 bytes
1349 bytes
Hoe kan je in C uit een oneindige lus stappen, door gewoon op een
willekeurige of bepaalde toets te drukken.
bv
...
while (1)
printf("Hallo");
...
Dus er moet steeds hallo geprint worden (andere functie uitvoeren) tot men
��n toets indrukt (willekeurige toets of bepaalde).
--
Blood, sweat & tears
Re: Uit lus breken via keypress
Author: Staf Wagemakers
Date: Sat, 05 Oct 2002 17:30
Date: Sat, 05 Oct 2002 17:30
47 lines
2073 bytes
2073 bytes
Gunter Schelfhout wrote:
>
> Hoe kan je in C uit een oneindige lus stappen, door gewoon op een
> willekeurige of bepaalde toets te drukken.
>
> bv
> ...
> while (1)
> printf("Hallo");
> ...
>
> Dus er moet steeds hallo geprint worden (andere functie uitvoeren) tot men
> ��n toets indrukt (willekeurige toets of bepaalde).
>
Met ncurses ( of een andere curses lib ) kan je dit doen door getch() in
nodelay mode te zetten. Hier beneden vind je een voorbeeldje compileren
met "cc -o name name.c -lcurses"
#include <ncurses.h>
int main()
{
int c;
if (!initscr()) {
fprintf(stderr,"initscr() failed\n");
exit(1);
}
keypad(stdscr,TRUE);
nl();
cbreak();
noecho();
nodelay(stdscr,TRUE);
scrollok(stdscr,TRUE);
for (;;) {
if((c=getch())!=ERR) break;
addstr("Hallo\n");
refresh();
}
endwin();
}
--
Staf Wagemakers
email : staf@patat.org
homepage : http://staf.patat.org
Re: Uit lus breken via keypress
Author: Hugo Marien
Date: Sat, 05 Oct 2002 18:45
Date: Sat, 05 Oct 2002 18:45
37 lines
1765 bytes
1765 bytes
Hi,
Kan eenvoudig:
do {
printf ("Hello\n")
.
.
while (!kbhit ())
if (!getch() ) getch() : maak keyboard buffer leeg
.
.
Hugo
"Gunter Schelfhout" <nospam@please.com> wrote in message
news:hTBn9.146883$8o4.21741@afrodite.telenet-ops.be...
>
> Hoe kan je in C uit een oneindige lus stappen, door gewoon op een
> willekeurige of bepaalde toets te drukken.
>
> bv
> ...
> while (1)
> printf("Hallo");
> ...
>
> Dus er moet steeds hallo geprint worden (andere functie uitvoeren) tot men
> ��n toets indrukt (willekeurige toets of bepaalde).
>
> --
> Blood, sweat & tears
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads