To begin our exploration of scanf(), we begin by reading an integer and a double from the console. Rather than attempt to explain how scanf() interprets the input, I believe it would be far better to first get an intuitive experience of how it works. We begin with the following program:
#include <stdio.h>
int main( void ) {
int anInteger = -1;
doubleaDouble = -1.0;
printf( "Enter an integer and a decimal number: " );
scanf( "%d%lf" , &anInteger , &aDouble );
printf( "1. integer:%d\n" , anInteger );
printf( "2.double:%lf\n" , aDouble );
}
This simple program first initializes values that will be used to store input. If scanf() can't assign values, we will see these default values. We will use two simple numbers for now. However, as we will see, if the user enters these numbers, we will be unable to tell whether they are default values that were not assigned by scanf() or...