Difference between revisions of "GNU C Programming Notes"
From Free Knowledge Base- The DUCK Project: information for everyone
Line 7: | Line 7: | ||
the ncurses function halfdelay() | the ncurses function halfdelay() | ||
+ | |||
+ | == getchar() example == | ||
+ | |||
+ | <nowiki>#include <stdio.h></nowiki> | ||
+ | <nowiki></nowiki> | ||
+ | <nowiki>#define EOL 10</nowiki> | ||
+ | <nowiki>#define ESC 27</nowiki> | ||
+ | <nowiki></nowiki> | ||
+ | <nowiki>main() {</nowiki> | ||
+ | <nowiki></nowiki> | ||
+ | <nowiki> char c = 'X';</nowiki> | ||
+ | <nowiki></nowiki> | ||
+ | <nowiki> while (c != ESC) {</nowiki> | ||
+ | <nowiki></nowiki> | ||
+ | <nowiki> int cnt;</nowiki> | ||
+ | <nowiki> cnt++;</nowiki> | ||
+ | <nowiki> printf("iteration of test %d", cnt);</nowiki> | ||
+ | <nowiki></nowiki> | ||
+ | <nowiki> c = getchar();</nowiki> | ||
+ | <nowiki></nowiki> | ||
+ | <nowiki> }</nowiki> | ||
+ | <nowiki> return 0;</nowiki> | ||
+ | <nowiki></nowiki> | ||
+ | <nowiki>}</nowiki> | ||
+ | <nowiki></nowiki> | ||
+ | |||
+ | == getputchar() example == | ||
+ | |||
+ | <nowiki>#include <stdio.h></nowiki> | ||
+ | <nowiki></nowiki> | ||
+ | <nowiki>main() {</nowiki> | ||
+ | <nowiki> int c;</nowiki> | ||
+ | <nowiki> c=getchar(); /*declare c to getchar() for character inputs*/</nowiki> | ||
+ | <nowiki> while(c != EOF){</nowiki> | ||
+ | <nowiki> putchar(c);</nowiki> | ||
+ | <nowiki> c=getchar();</nowiki> | ||
+ | <nowiki> }</nowiki> | ||
+ | <nowiki>}</nowiki> | ||
+ | <nowiki></nowiki> | ||
+ | |||
+ | == | ||
== References == | == References == |
Revision as of 18:36, 20 June 2007
Text Notes Document for Gnu C Programming
getchar() and loop control
C program that needs to attend the user input without blocking a loop depends on which environment you're coding: raw-C for the glass-tty, curses/termcap, X, KDE, Gnome, etc.
the ncurses function halfdelay()
getchar() example
#include <stdio.h> #define EOL 10 #define ESC 27 main() { char c = 'X'; while (c != ESC) { int cnt; cnt++; printf("iteration of test %d", cnt); c = getchar(); } return 0; }
getputchar() example
#include <stdio.h> main() { int c; c=getchar(); /*declare c to getchar() for character inputs*/ while(c != EOF){ putchar(c); c=getchar(); } }
==
References
- Introduction to ANSI C (on linux)