+ 2
The [] brackets define character classes, just like in regular expressions (regex).
Eg : scanf("%[A-Za-z0-9],&a);
/* scanf is to accept only
alphanumeric characters */
The ^ metacharacter in [^\n] specifies that scanf in this case should read all possible characters except a newline, and when a newline is finally received, it stops.
Eg - scanf("%[^A-Za-z],&a);
/* scanf is to accept only
numeric or special characters */
If you omit the ^, scanf() will only accept newline characters and stop when any other character is typed.
That is why to read spaces, the following character class was used.