primers

CSDN recently launched a question and answer board, which I didn’t pay much attention to, but I received an advertisement a few days ago. I clicked on it and found that the answer was accepted for the first time and I got a red envelope in cash! And such good things! Considering the balance of less than 5 yuan in my CSDN wallet, it is one step closer to the withdrawal threshold of 100 yuan! Three fen a day, a million worth, just around the corner ah!

Looking for problems

Say dry dry, so I ran to the q&A version began to look for problems, in order to ensure the rate of adoption, I chose to turn a circle, choose a look at the relatively small white problem, ha ha, thinking that this is not easy ah! Junior high school physics came in handy!

Problem processing

Wait… Celsius to Fahrenheit… Sorry, junior high school physics teacher… Google it…

The Celsius (°C) and Fahrenheit (°F) scales can be converted as F=C×1.8+32 C=(F-32)÷1.8Copy the code

Okay, I got the formula, and THEN I typed through the questioner’s code to see if he made any mistakes.

Debug a wave. It’s still 32. On reflection: The formula is ok… So that’s C no. Add print!Sure enough, C is always 0, so it must be the wrong gesture. In fact, SCANf has not been used for a long time. It was only used when I started to learn C to write a demo. But double%fFloat, float, float%fWell… Double can be assigned to float with loss of precision, but is used%fWill it be unusual? So, Baidu next scanf and double… Sure enough double numbers should be used%lf. Modify debug a wave immediatelyCompleted. Little hands shake, red envelopes come!

Afterword.

For the small white we just started, out of the bug, should give priority to add print information or F5 debugging, the problem location cutting positioning, and then for some function parameter list to clear the use of objects, can not take it for granted ah!

Extend the scanf article

After searching scanf online for a long time, I found that the official original version is reliable and contains the most complete content, especially the part involving length modification (for example, the input of double number, the general document does not write, just example float, if you know how to do double, sorry, please re-baidu keyword). Even my favorite beginner programmer isn’t complete. Ouch. Attached is the official document in English, students who need to dig deeply can directly go to the official link at the end of the article to study!

A format specifier for scanf follows this prototype:

%[*][width][length]specifier

Where the specifier character at the end is the most significant component, since it defines which characters are extracted, their interpretation and the type of its corresponding argument: Except for n, at least one character shall be consumed by any specifier. Otherwise the match fails, and the scan ends there.

The format specifier can also contain sub-specifiers: asterisk (*), width and length (in that order), which are optional and follow these specifications:

This is a chart showing the types expected for the corresponding arguments where input is stored (both with and without a length sub-specifier): Note: Yellow rows indicate specifiers and sub-specifiers introduced by C99.

The official authority: www.cplusplus.com/reference/c…