The first type:
[CPP]View PlainCopy
- Char szstring[] = "3.1415926535898";
- Double db1;
- DB1 = Atof (szstring);
- printf ("Atof result:\n");
- printf ("%f%.12f%.2f%e%e\n", DB1, DB1, DB1, DB1, DB1);
- printf ("%.1e%.1e%.18e%.18e\n", DB1, DB1, DB1, DB1);
The second type:
[CPP]View PlainCopy
- Char szstring2[] = "3.1415926535898";
- Double DB2;
- SSCANF (SzString2, "%lf", &DB2);
- printf ("\nsscanf result:\n");
- printf ("%f%.12f%.2f%e%e\n", DB2, DB2, DB2, DB2, DB2);
- printf ("%.1e%.1e%.18e%.18e\n", DB2, DB2, DB2, DB2);
There are many magical functions for the SSCANF function. Let's look at the use of the encyclopedia:
1. Common usage.
Char buf[512];
SSCANF ("123456", "%s", buf);//Here buf is the name of the array, which means to deposit 123456 in buf in the form of%s!
printf ("%s\n", buf);
The result is: 123456
2. Take a string of the specified length. As in the following example, take a string with a maximum length of 4 bytes.
SSCANF ("123456", "%4s", buf);
printf ("%s\n", buf);
The result is: 1234
3. The string to take to the specified character. As in the following example, the string is encountered until the space is met.
SSCANF ("123456 Abcdedf", "%[^]", buf);
printf ("%s\n", buf);
The result is: 123456
4. Take a string that contains only the specified character set. As in the following example, take a string that contains only 1 to 9 and lowercase letters.
SSCANF ("123456abcdedfBCDEF", "%[1-9a-z]", buf);
printf ("%s\n", buf);
The result is: 123456ABCDEDF
When entering:
SSCANF ("123456abcdedfBCDEF", "%[1-9a-z]", buf);
printf ("%s\n", buf);
The result is: 123456
5. The string to be taken to the specified character set. As in the following example, take a string that encounters an uppercase letter.
SSCANF ("123456abcdedfBCDEF", "%[^a-z]", buf);
printf ("%s\n", buf);
The result is: 123456ABCDEDF
6, given a string iios/[email protected], gets/And the string between @, first filter out "iios/", and then send a string of non-' @ ' to BUF
SSCANF ("Iios/[email protected", "%*[^/]/%[^@]", buf);
printf ("%s\n", buf);
The result is: 12DDWDFF
C + + string converted to floating point type