当前位置:网站首页>[printf function and scanf function] (learning note 5 -- standard i/o function)
[printf function and scanf function] (learning note 5 -- standard i/o function)
2022-06-13 01:48:00 【It's Beichen bupiacra】
standard I/O function
One 、printf function
printf Functions are often called “ Format print function ”, Its first parameter is called “ Formatted string ”, stay “ Formatted string ” Can be used in “ Place holder ” Insert some other types of data into the text string for printout .“ Place holder ” It's all about “%” At the beginning , When the program prints out , these “ Place holder ” Will be replaced by real data .
printf Function :
| Place holder | Show content |
|---|---|
| %c | character |
| %f | Floating point numbers |
| %s | character string |
| %x | Hexadecimal number |
| %d | Integers |
| %o | Octal number |
| %u | Unsigned integer |
| %% | % character |
printf Modifier of function :
| Modifier | significance |
|---|---|
| digit( Numbers ) | Specifies the output width of the data , In characters . If the specified width is not enough , Subject to the actual width |
| .digit( Numbers ) | Specify the output precision of the data , For floating-point numbers, the number of significant decimal places , For a string, it refers to the number of output characters , For integers, the minimum number of bits of output ( Not enough digits , High compensation 0) |
| - | Specifies that the data alignment is left aligned . The default data output is right aligned |
| + | For signed data , Positive 、 Minus sign |
| # | Display the prefix of the data , Display prefix for octal numbers 0, Display prefix for hexadecimal numbers 0x or 0X |
These modifiers are used with placeholders , Not to be used alone .
Two 、scanf function
In the use of scanf When using functions, pay attention to , You need to add a before the parameter variable name “&” Symbol , Indicates the memory address of the variable .
char ch;
int n;
float flt;
scanf("%c%d%f",&ch,&n,&flt);
Users should pay attention to , Blank characters should be left between each data ( For example, the space character ).
scanf Function when reading character data , The first character entered by the user ( Include white space characters ) Read in , And save to the character variable . The so-called white space characters include spaces 、 Invisible characters such as horizontal tabs and line breaks .
scanf Function when reading non character data , The leading white space characters in the user input are automatically skipped , Read from the first legal character , Do not stop reading until white space or illegal characters are encountered , Then these characters are converted into corresponding data and saved in variables . What are legal characters ? for example , If you read a decimal integer , Legal characters mean 0 To 9 These numeric characters ; If you read an octal number , Legal characters mean 0 To 7 These numeric characters ; If you read a hexadecimal number , Legal characters mean 0 To 9 These numeric characters and A To F、a To f These characters ; If you read a floating point number , Then the legal characters include 0 To 9 Except for these numeric characters , It also includes a decimal point “.” The characters of .
scanf Try not to include characters other than placeholders in the format string of the function , Because the user must input strictly according to the format of the formatted string , Otherwise, it will easily lead to errors .
边栏推荐
- Use mediapipe+opencv to make a simple virtual keyboard
- [wsl2] restrict wsl2 accessible hardware resources (cpu/ memory)
- 什么是立体角
- Implementation and design of JMeter interface test database assertion for CSDN salary increase technology
- Super complete regular expressions
- About the proposed signature file migration to industry standard format pkcs12
- How do you use your own data to achieve your marketing goals?
- What is the path field—— Competitive advertising
- 指针链表的实现
- Delphi7 compressed pictures (BMP, JPG, PNG)
猜你喜欢

Devexpress implementation flow chart

30: Kakfa simulates JSON data generation and transmission

redis

Detailed understanding of white noise

What is Google plus large text ads? How to use it?

Machine learning basic SVM (support vector machine)

Magics 23.0如何激活和使用视图工具页的切片预览功能

MySQL download and installation

Introduction to Google unit testing tools GTEST and gmoke

Temporary objects and compilation optimization
随机推荐
水管工遊戲
JSON and protobuf Any interchange
Quickly set the computer to turn off automatically
Wildcard usage of go standard library FMT
cin,cin. get(),cin. Summary of the use of getline() and getline()
Anims of phaser3
谷歌的受众群体是如何发挥作用的?
Compiling minicom-2.7.1 under msys2
Opencv camera calibration (1): internal and external parameters, distortion coefficient calibration and 3D point to 2D image projection
What is Google plus large text ads? How to use it?
指针链表的实现
A DPU architecture without CPU: Hyperion
D template instance does not match declaration
Devaxpress Chinese description --tdximageslider (picture rotation control)
Delphi implements adding a column of serial number to the CXGRID list
Detailed explanation of audience characteristics
This of phaser3 add. add. image
Run Presto under docker to access redis and Bi presentation
Padavan mounts SMB sharing and compiles ffmpeg
Introduction to ROS runtime