The scanset conversion facility provided by scanf() is a useful string input method although it can appear dauntingly complex. This conversion facility allows the programmer to specify the set of characters that are (or are not) acceptable as part of the string. A scanset conversion consists of a list of acceptable characters enclosed within square brackets. A range of characters may be specified using notations such as "a-z" meaning all characters within this range. The actual interpretation of a range in this context is implementation specific, i.e. it depends on the particular character set being used on the host computer. If you want an actual "-" in the scanset it must be the first or last character in the set. If the first character after the "[" is a "^" character then the rest of the scanset specifies unacceptable characters rather than acceptable characters.
The use of scansets is shown by this program, called str3.
main()
{
char strspace[50];
printf("Enter a string in lower case ");
scanf("%[ a-z]",strspace);
printf("The string was >>%s<<\n",strspace);
}
And a typical dialogue is shown here. $ str3 Enter a string in lower case hello world The string was >>hello world<< $ str3 Enter a string in lower case hello, world The string was >>hello<< $ str3 Enter a string in lower case abcd1234 The string was >>abcd<< $Note that, in all cases, conversion is terminated by input of something other than a space or lower-case letter.