Sscanf is a useful function that can be used to retrieve integers, floating-point numbers, and strings from strings. It is easy to use, especially for integers and floating-point numbers. However, beginners may not know some advanced usage when processing strings. Here is a brief description. 1. Common usage. The following is a reference clip: Char STR [512] = {0 }; Sscanf ("123456", "% s", STR ); Printf ("str = % s/n", STR ); 2. Take a string of the specified length. In the following example, a string with a maximum length of 4 bytes is obtained. The following is a reference clip: Sscanf ("123456", "% 4 s", STR ); Printf ("str = % s/n", STR ); 3. Obtain the string of the specified character. For example, in the following example, the string is obtained when a space is encountered. The following is a reference clip: Sscanf ("123456 abcdedf", "% [^]", STR ); Printf ("str = % s/n", STR ); 4. Take a string that only contains the specified character set. For example, in the following example, take a string that only contains 1 to 9 letters and lowercase letters. The following is a reference clip: Sscanf ("123456 abcdedfbcdef", "% [1-9a-z]", STR ); Printf ("str = % s/n", STR ); 5. Obtain the string of the specified character set. For example, in the following example, a string with uppercase letters is used. The following is a reference clip: Sscanf ("123456 abcdedfbcdef", "% [^A-Z]", STR ); Printf ("str = % s/n", STR ); Conversion http://dev.yesky.com/ |