The number of times the number is retrieved:
# Include <stdio. h> # include <stdlib. h> char * tokenstring = "12:34:56-7890"; char A1 [3], A2 [3], A3 [3]; int I1, I2; void main (void) {clrscr (); sscanf (tokenstring, "% 2 S: % 2 S: % 2 s-% 2D % 2D", A1, A2, A3, & I1, & I2); printf ("% s/n % d/n", A1, A2, A3, i1, i2); getch ();}
Retrieve the number in the time.
Shift (20, 4, 5, 7)
Pitfalls ~~ Note the application of the sscanf function, and then read the integer and floating point numbers in the string.
The stdlib function contains the following two items:
Atoi () converts the integer in the string
Atof () converts the floating point in the string
Retrieve
Shift (20, 4, 5, 7)
# Include <stdio. h> # include <string. h> # include <stdlib. h> int main () {char * A = "shift (100, 100)", B [], C [], Judge; int Len, num, C2; judge = 2; sscanf (a, "% [^ 0-9]", B); printf ("% s", B); Len = strlen (B ); A + = Len; while (Judge! = 1) {judge = sscanf (a, "% [0-9] % [',']", B, c ); printf ("Judge = % d \ n", judge); scanf ("% d", & C2); Len = strlen (B); num = atoi (B ); A + = Len + 1; printf ("num = % d % s \ n", num, c); // If (Judge = 1) break ;}}
Previous:Poj 2352 star tree array variant Application
Next article:Challenge programming: Programming Competition Training Manual-question (Chapter 1-Chapter 8)