Reading Characters
getchar and putchar.
Reading Single Characters
C provides getchar() to read one character at a time from standard input, and putchar() to write one character to standard output.
Both live in <stdio.h>.
#include <stdio.h>
int main(void) {
putchar('H');
putchar('i');
putchar('\n');
return 0;
}putchar Basics
putchar(c) writes the character c and returns the character written, or EOF on error.
It is the simplest way to output a single byte.
#include <stdio.h>
int main(void) {
for (char c = 'A'; c <= 'E'; c++) {
putchar(c);
}
putchar('\n');
return 0;
}All lessons in this course
- Characters as Integers
- The ctype Library
- Reading Characters
- Building Char Utilities