ABSTRACT

This chapter focuses on using the scanf() function to get input from the user, store that input in variables, and use it in once programs. scanf() is a powerful function that offers many ways to read and store data in program variables. The first is a format string similar to that of printf(), followed by the memory addresses of the variables in which the input data will be stored. The scanf() function is used to read data from standard input stream (stdin) and store that data in program variables. By default, the stdin stream is associated with the keyboard. The input data are read according to a particular format, very similar to the way output is handled with printf(). scanf() returns the number of data items that were successfully read and assigned to program variables. scanf() returns prematurely if the input values do not match the types or order of the conversion specifiers.