Question: When Using scanf to input a string, if a space is encountered in the input, scanf will put the character before the space into the character array behind it. So what should we do if we do not want to end the input with space, but with the last carriage return as the end of the input string? I have also seen this question in some BBs or forums. Generally, the answer is gets (). In fact, scanf can fully implement this function. The statement is as follows: scnaf ("% [^/n] S", STR); this function is described in detail now. First, this function is for % S. you can insert [] between % and S. The brackets contain a character set. If the letters in the input string are in this character set, it will be read in. When the first letter is not in this character set, the input will end. For example: scanf ("% [ABC] S", STR); input: abccbadef; input: abccba; two special characters in brackets: ^ and-^ indicate none, the letters in this character set cannot be accepted. This function must appear immediately after [, otherwise it will be treated as a general character. In the above example, [^/n] indicates that as long as the carriage return is not met, the entered characters will be accepted. -Indicates a connector, for example, 0-9 A-Z. It indicates a range. All characters in this range are accepted or not accepted. If you want to treat "-" as a general character, "-" must appear immediately before. In addition, if you want to use parentheses as common characters, they must appear immediately after [or ^. The usage of scanf can be found in msdn, but it is not very obvious. At least three links can be found on that page, and I just gave a rough description and didn't explain it in detail. I have a detailed explanation of this problem on the Linux man page. If you are interested, go and check it out. In addition, this is an article that I accidentally saw in the previous stage. I excerpted it and forgot to remember the source ...... Today, I decided to post my notes to my blog and share them with you. If the author does not specify the detailed source, I am sorry!