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: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!