userland: move getchar from cpp-cheat

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-05-05 00:00:00 +00:00
parent e611806df9
commit fb3fdaa8a6
3 changed files with 41 additions and 0 deletions

21
userland/c/getchar.c Normal file
View File

@@ -0,0 +1,21 @@
/* Get on character from stdin, and then print it back out.
*
* Same as getc(stdin).
*
* You have to press enter for the character to go through:
* https://stackoverflow.com/questions/1798511/how-to-avoid-pressing-enter-with-getchar
*
* Used at:
* https://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1/53937376#53937376
*/
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char c;
printf("enter a character: ");
c = getchar();
printf("you entered: %c\n", c);
return EXIT_SUCCESS;
}