Dark Horse programmer--"Dark Horse video note" The use of the scanf function of C language Foundation

Source: Internet
Author: User

0. The pits that I actually encountered

If you use a standard keyboard with a Mac, you cannot enter with the scanf on the keypad, or the system will not be well recognized.

1. Basic use of scanf function

   1:  //define a variable to hold the integer entered by the user
   2:      int number;
   3:      
   4:      //The SCANF function accepts only the address of the variable
   5:      //The scanf function is a blocking function that waits for user input
   6:      //When user input is complete, the value entered by the user will be assigned to the number variable
   7:      //function call complete
   8:      scanf ("%d", &number);

2. Other usage and attention points of scanf

   1:  /* 1. Enter characters
   2:      char Myc;
   3:      
   4:      scanf ("%c", &MYC);
   5:      
   6:      printf ("Input character is%c\n", MYC);
   7:       * /
   8:      
   9:  /    * 2. Enter multiple values at once, separated by some symbols
  Ten:      int num1, num2;
  11:       
  :      scanf ("%d#%d", &num1, &num2);
  13:      
  :      printf ("num1=%d, num2=%d\n", NUM1, num2);
  :      * /
  16:      
+   /      *
3.    If the scanf parameter is separated by a space, the actual input can be delimited by a space, tab, carriage return   
  :      int num1, num2;
  :      scanf ("%d%d", &NUM1, &num2);
  :      printf ("num1=%d, num2=%d\n", NUM1, num2);
  :       * /
  23:      
  :/      *
4.SCANF   :      cannot write \ n
  :      int A;
  :      scanf ("%d\n", &a);//Wrong wording
  :      printf ("A's value is%d\n", a);
  :       * /

Dark Horse programmer--"Dark Horse video note" The use of the scanf function of C language Foundation

Related Article

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.