tailieunhanh - Lecture Elementary programming with C - Session 4: Input and output in C

Lecture Elementary programming with C - Session 4: Input and output in C. After completing this chapter, students will be able to: understand formatted I/O functions - scanf and printf, use character I/O functions - getchar and putchar. | Input and Output in 'C' Session 4 Input and Output in C Objectives To understand formatted I/O functions - scanf() and printf() To use character I/O functions - getchar() and putchar() Elementary Programming with C/Session 4/ of 27 Standard Input/Output In C, the standard library provides routines for input and output The standard library has functions for I/O that handle input, output, and character and string manipulation Standard input is usually the keyboard Standard output is usually the monitor (also called the console) Input and Output can be rerouted from or to files instead of the standard devices Elementary Programming with C/Session 4/ of 27 The Header File #include This is a preprocessor command is a file and is called the header file contains the macros for many of the input/output functions used in ‘C’ printf(), scanf(), putchar(), getchar() functions are designed such that, they require the macros in for proper execution Elementary Programming with C/Session 4/ of 27 Formatted Input/Output printf() – for formatted output scanf() – for formatted input Format specifiers specify the format in which the values of the variables are to be input and printed Elementary Programming with C/Session 4/ of 27 printf ()-1 used to display data on the standard output – console Syntax printf ( “control string”, argument list); The argument list consists of constants, variables, expressions or functions separated by commas There must be one format command in the control string for each argument in the list The format commands must match the argument list in number, type and order The control string must always be enclosed within double quotes, which are its delimiters Elementary Programming with C/Session 4/ of 27 The control string consists of one or more of three types of items: Text characters: consists of printable characters Format Commands: begins with a % sign and is followed by a format code - . | Input and Output in 'C' Session 4 Input and Output in C Objectives To understand formatted I/O functions - scanf() and printf() To use character I/O functions - getchar() and putchar() Elementary Programming with C/Session 4/ of 27 Standard Input/Output In C, the standard library provides routines for input and output The standard library has functions for I/O that handle input, output, and character and string manipulation Standard input is usually the keyboard Standard output is usually the monitor (also called the console) Input and Output can be rerouted from or to files instead of the standard devices Elementary Programming with C/Session 4/ of 27 The Header File #include This is a preprocessor command is a file and is called the header file contains the macros for many of the input/output functions used in ‘C’ printf(), scanf(), putchar(), getchar() functions are designed such that, they require the macros in for proper execution .

TỪ KHÓA LIÊN QUAN