...

/

Discussion: Deciphering scanf()

Discussion: Deciphering scanf()

Execute code to understand the output and gain insights into input pattern matching.

Run the code

Now, it's time to execute the code and observe the output.

#include <stdio.h>

int main()
{
  char buffer[32];
  printf("Type something: ");
  scanf("%[ABC]", buffer);
  printf("You typed: %s\n", buffer);

  return(0);
}
C code for the given puzzle

Understanding the output

The program prompts for input, but only uppercase letters ABC are allowed:

Type something: ALPHA
You typed: A
Code output

Note: Any character input other than ABC ...