C - Write program to prompt for three characters


Write a program that prompts for three characters. For example:

I'm waiting for three characters: 

Code three consecutive getchar() functions to read the characters.

Format the result like this:

The three characters are 'a', 'b', and 'c' 

where these characters - a, b, and c - would be replaced by the program's input.


#include <stdio.h>

int main()/*from  w  ww .ja v  a 2 s.  co m*/
  int a, b, c;

  printf("I'm waiting for three characters: ");
  a = getchar();
  b = getchar();
  c = getchar();
  printf("The three characters are '%c', '%c', and '%c'\n", a, b, c);


Related Exercise