TAILIEUCHUNG - Lecture Introduction to computing systems (2/e): Chapter 18 - Yale N. Patt, Sanjay J. Patel
Chapter 18 - I/O in C. This chapter presents the following content: Standard c library, basic I/O functions, text streams, character I/O, buffered I/O, input buffering, output buffering, formatted I/O, special character literals, missing data arguments,.and other contents. | Chapter 18 I/O in C Standard C Library I/O commands are not included as part of the C language. Instead, they are part of the Standard C Library. A collection of functions and macros that must be implemented by any ANSI standard implementation. Automatically linked with every executable. Implementation depends on processor, operating system, etc., but interface is standard. Since they are not part of the language, compiler must be told about function interfaces. Standard header files are provided, which contain declarations of functions, variables, etc. 18- Basic I/O Functions The standard I/O functions are declared in the header file. Function Description putchar Displays an ASCII character to the screen. getchar Reads an ASCII character from the keyboard. printf Displays a formatted string, scanf Reads a formatted string. fopen Open/create a file for I/O. fprintf Writes a formatted string to a file. fscanf Reads a formatted string from a file. 18- Text Streams All character-based I/O in C is performed on text streams. A stream is a sequence of ASCII characters, such as: the sequence of ASCII characters printed to the monitor by a single program the sequence of ASCII characters entered by the user during a single program the sequence of ASCII characters in a single file Characters are processed in the order in which they were added to the stream. ., a program sees input characters in the same order as the user typed them. Standard input stream (keyboard) is called stdin. Standard output stream (monitor) is called stdout. 18- Character I/O putchar(c) Adds one ASCII character (c) to stdout. getchar() Reads one ASCII character from stdin. These functions deal with "raw" ASCII characters; no type conversion is performed. char c = 'h'; . putchar(c); putchar('h'); putchar(104); Each of these calls prints 'h' to the screen. 18- Buffered I/O In many systems, characters are buffered in memory during an I/O operation. Conceptually, each
đang nạp các trang xem trước