Input with fgetc()

scanf() isn't the only game in town when it comes to input. Another common input function I highly recommend knowing is the venerable fgetc(), which specializes in reading just a single character (ie byte of data) from a specified file pointer.

1
#include <stdio.h>
 
int main()
{
    char a, b, c, d;
 
    fprintf(stdout, "Enter a char:");
    a = fgetc(stdin);
 
    fprintf(stdout, "Enter a char:");
    b = fgetc(stdin);
 
    fprintf(stdout, "Enter a char:");
    c = fgetc(stdin);
 
    fprintf(stdout, "Enter a char:");
    d = fgetc(stdin);
 
    fprintf(stdout, "You entered ASCII chars %hhu, %hhu, %hhu, and %hhu\n", a, b, c, d);
 
    return(0);

Questions