Escape characters are a common problem. If I remember correctly, I made several mistakes. I reviewed them carefully tonight. The escape characters that need attention are as follows: , , , , f, \, ', ", ddd, xhh. These escape characters have fixed values in ASCII. It is easy to make mistakes when solving the string length. Each escape character has its own function. It should be noted that in the two escape characters ddd and xhh, the d in ddd is only three numbers from 0 to 7, and the h in xhh can be a character from 0 to 9a to f. However, it should be noted that xhh can be two characters or one character, which requires us to analyze in actual situations. In ddd, it should be noted that the values of the three digits after it cannot be greater than 7.
For example, the following string:
char Str[]="abc f \'"123789x78xfg";
The length of the string above is 18. This is a more complicated situation. In this more complicated situation, only by understanding the role of the escape character can the length of the string be calculated. Therefore, we need to consider the problem of escape characters when analyzing the length of the string.
The format of printf, the return value of this function is the number of bytes in the string, this return can be used to implement multiple printing of the string in sprintf , you can refer to Ruijie's written test questions. There are various formats for printf printing, among which the more easily tested ones are additional format description characters:
l is used to implement long integers and can be added before the format characters d, o, x, and u.
m (a positive integer) is the minimum width of the data.
n (represents a positive integer) For real numbers, it means outputting n decimal places; for strings, it means the number of strings to be truncated.
- The output numbers or characters are aligned to the left in the field.
The above four additional formats are often tested in the written test. Although they are small problems, they are the places where we lose points, which shows that our basics are not up to standard. Especially when the string is output in the additional format, it is easy to make mistakes.
%ms, the output string occupies m columns. If the string length is greater than m, the limit of m will be exceeded and the string will be output in its entirety. If the string length is less than m, spaces will be added to the left.
%-ms, if the string length is less than m, the string will be moved to the left and filled with spaces on the right in the return value of m.
%m.ns, the output occupies m columns, but only takes n characters from the left end of the string. These n characters are output at the right end of the m column, with spaces padded on the left.
%-m.ns, where m, n and %m.ns are the same, n characters are output at the left end of m columns, and spaces are added on the right. When n>m, m automatically takes the value of n, that is, n characters are output normally.
%m.nf, the output data occupies m columns, with n decimal places. If the data length is less than m, spaces are added on the left.
%-m.nf and %m.nf just make the output value lean to the left end and fill spaces on the right end.
It should also be noted that the percent sign is printed using "%%".
The format setting of scanf is similar to that of printf, but there are also some differences. scanf cannot limit the width of the decimal point, only the width of the bit field, and no n value. You also need to pay attention to the existence of an ignore symbol "*", such as %*3d, which ignores the 3-digit integer and skips the assignment to the variable.
l is used to input length-shaped data
h is used to input short integer data
field width specifies the width of the input data. The field width is a positive integer.
* Indicates that this input item will not be assigned to the corresponding variable after being read.
Today I will briefly summarize the basic format. Although these are the most basic knowledge, this is all you can do for a written test.
Previous article:The difference between kernel logical address and kernel virtual address
Next article:Application of accompanying array and counting sort
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Can supercapacitors accelerate cars?
- There are two questions about the frequency division circuit, as shown in the figure
- MicroPython Hands-on (24) - Expanding the Control Panel with the Control Panel
- [Flower carving hands-on] Interesting and fun music visualization series of small projects (14) --- water cup and bottle lamp
- Does TMS320C6748 support TFTP instance in stareware?
- Asynchronous Serial Transceiver Design Report.docx
- Design of robotic arm gesture tracking and voice control system
- A new trend in home appliances, PI opens up your new life in home appliances! Download product information and answer questions to win prizes!
- Voltage acquisition circuit
- Problems with IO pin configuration when STM32 is low power