/* SCANF.C: This program receives formatted input using scanf. */ #include void main( void ) { int i; float fp; char c, s[81]; int result; printf( "Enter an integer, a floating-point number, " "a character and a string:\n" ); result = scanf( "%d %f %c %s", &i, &fp, &c, s ); printf( "\nThe number of fields input is %d\n", result ); printf( "The contents are: %d %f %c %s\n", i, fp, c, s ); } /* Program Code Action scanf( "%Ns", &x ); Read a string into near memory scanf( "%Fs", &x ); Read a string into far memory scanf( "%Nd", &x ); Read an int into near memory scanf( "%Fd", &x ); Read an int into far memory scanf( "%Nld", &x ); Read a long int into near memory scanf( "%Fld", &x ); Read a long int into far memory scanf( "%Nhp", &x ); Read a 16-bit pointer into near memory scanf( "%Nlp", &x ); Read a 32-bit pointer into near memory scanf( "%Fhp", &x ); Read a 16-bit pointer into far memory scanf( "%Flp", &x ); Read a 32-bit pointer into far memory Note that %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]. This is a common scanf extension, but note that it is not required by the ANSI standard. To store a string without storing a terminating null character ('\0'), use the specification %nc, where n is a decimal integer. In this case, the c type character indicates that the argument is a pointer to a character array. The next n characters are read from the input stream into the specified location, and no null character ('\0') is appended. If n is not specified, the default value for it is 1. */