The difference between scanf and getchar

angryTom
Release: 2020-02-13 15:02:14
Original
10598 people have browsed it

The difference between scanf and getchar

The difference between scanf and getchar

##1. Different function formats

scanf The function is a format input function, which inputs data from the keyboard into the specified variable according to the format specified by the user.

The getchar function is a keyboard input function, its function is to input a character from the keyboard.

2. Different reading methods

The scanf function will skip spaces, tabs and newlines when reading numbers.

The getchar function can only input characters. When inputting, the characters are extracted from the buffer in sequence when the Enter key is encountered.

3. Different ways to end input

The scanf function ends an input with spaces, Enter, and Tab, and does not accept spaces.

The getchar function ends the input with Enter (no space ends) and accepts spaces.

4. There are different methods of discarding the carriage return character

The scanf function ends an input with Space, Enter, and Tab, and will not discard the last carriage return character (i.e. return The car symbol will remain in the buffer).

When the getchar function ends the input with Enter, it accepts spaces and discards the final carriage return character.

Recommended learning:

c language video tutorial

The above is the detailed content of The difference between scanf and getchar. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!