Windows C Input Note

Source: Internet
Author: User

Windows console input, which is opened in text mode by default, cannot be read to the CR when entered, even if the text mode is not changed, because Windows has converted CRLF to a single LF.

If Freopen ("CON", "RB", stdin); You can read the CR

Fgets will absorb line breaks, but line breaks are also written to the string

If not string, scanf ("%d", &d); Gets () best. vs2015 Delete gets, with gets_s can.

First: Fgets reads a string with ' \ n '. That is, in the case of no more than the second argument, Fgets reads the characters from the third argument (the file pointer, the input stream) continuously. until ' \ n' is encountered and ' \ n ' is removed from the input stream .

Second: The gets function does not detect the number of characters that are read in. Just continuously read characters from the standard input stream (keyboard) until ' \ n ' is encountered. Unlike fgets, the Get function will take ' \ n ' out of the input stream, but only remove it and discard it. is not saved in the target string (the code above is both str).

Finally: The scanf function does not detect the number of characters that are read in. Just continuously read characters from the standard input stream (keyboard) until you encounter a " white space character ." Unlike Fgets/gets, scanf does not remove " whitespace " from the input stream.

Always keep in mind that the ' \ R ' is a whitespace character, and the scanf function will not read into it. But the fgets and gets function reads it!

http://blog.csdn.net/lanceleng/article/details/8730192

scanf

SCANF will leave the line break in the input buffer, and%s will leave

Most of the conversion specifiers skip leading whitespace including newlines and does not %c .

In a formatted string, most directives will ignore whitespace (isspace), except%c

Preceded by a space, the leading whitespace is ignored, including line breaks.

while (scanf ("%c", &c)!=-1)
printf ("%c", c);

Pressing CTRL + Z does not end

The following sequence can end

CTRL + Z, CR

Ctrl+z,cr

Ctrl+d

Windows C Input Note

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.