Application of the sscanf () function atoi () atof ()

Source: Internet
Author: User

 
 
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)
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.