In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly talks about "what are the differences between c language gets () and scanf ()". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what's the difference between gets () and scanf ()?"
Mainly for "% c": there are no delimiters by default (including all white space characters).
Situation one
Char a,b
Scanf ("% c% c", & aPhoneShab)
Printf ("% c% c", ameme b)
The character input does not have any delimiters.
Case two
Char a,b
Scanf ("% c% c", & aPhoneShab)
Printf ("% c% c", ameme b)
Special: as long as any white space character appears between the characters% c in scanf (), then any white space character (and unlimited number) on the input side is used as a delimiter {the situation at this time is similar to "% d% d", which can intelligently recognize and read the "true" character}-but! The first character of the new round will still be a carriage return.
To sum up, it is better to read multiple characters in the future.
The method of managing extra useless characters in buffer zone
(1) clear the buffer-there is a function called fflush (stdin) that can be used to empty the buffer.
While (scanf ("% c% c", & a <...)! = EOF)
{
Printf ("averse% cdirection billing% c\ n", aPermie b)
Fflush (stdin)
Printf ("Input the value of an and b:")
}
That is, temporarily empty the buffer before the white space character is misread.
(2) read out the error data of the buffer (indirectly clean the buffer)-- getchar () or gets ()
For getchar (): read the first character of the buffer (EOF), the return value of this function is the character (EOF==-1) (its corresponding ASCII code if returned to an integer variable) the extended sibling function putchar (): putchar (ch/int)-- this function outputs the charvalue corresponding to the parameter ch/int (ASCII code) at the terminal.
For gets (): get the string (read a line of things).
In the C language, both the scanf () function and the gets () function can be used to input strings, but there are many differences.
The main differences between scanf () and gets () are as follows:
The input delimiter for 1.gets () is only carriage returns, so gets can read in spaces. If you enter "Hello World" using gets (), the result is "Hello World" after running, but only "Hello" can be output using scanf () input.
2.scanf () and gets () also treat buffer carriage returns completely differently. Scanf () ignores carriage returns before reading non-white space characters, and stops typing if white space characters are encountered after reading, leaving them in the buffer. Gets () simply ends typing as soon as it encounters a carriage return and removes the carriage return from the buffer.
3.gets () can read empty carriage returns, but scanf cannot.
At this point, I believe you have a deeper understanding of the difference between c language gets () and scanf (). You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.