/* Kenneth L Moore CIT 145 file scan.c - features of scanf 20/01/02 20:06 */ #include int main() { //char c1, c2; int i, j, k; int ret; //long l; float f; char str[256]; printf( "\nEnter some floats...-1.0 or Ctl Z to stop\n" ); while ( (( ret = scanf( "%f", &f ) ) != EOF) &&(f!=-1.0)) /* continue till end-of-file */ { if ( ret == 1 ) { printf( "You entered %.7g\n", f ); } else { printf( "What was that? Try again...\n" ); fflush( stdin ); } } printf( "\nEnter dates as MMDDYY (no slashes) 13 or Ctl Z to stop\n" ); while( (( ret = scanf( "%2d%2d%2d", &i, &j, &k ) ) != EOF)&&(i!=13) ) { if ( ret == 3 ) { printf( "You entered %02d-%02d-%02d\n", i, j, k ); } else { printf( " Try again...\n" ); fflush( stdin ); } } printf( "\nEnter dates as MM/DD/YY (with slashes) 13 or Ctl Z to stop\n" ); while( ( ret = scanf( "%2d/%2d/%2d", &i, &j, &k ) ) != EOF &&(i!=13) ) { if ( ret == 3 ) { printf( "You entered %02d-%02d-%02d\n", i, j, k ); } else { printf( "As if! Try again...\n" ); fflush( stdin ); } } printf( "\nEnter a series of strings ? or Ctl Z to stop\n" ); while ( (scanf( "%s", str) ) != EOF && (str[0]!='?')) { printf( "[%s]\n", str ); } printf( "\nEnter a series of strings of 6 chars or less ? or Ctl Z to stop\n" ); while ( (scanf( "%6s", str) ) != EOF && (str[0]!='?') ) /* take at most 6 chars */ { printf( "[%s]\n", str ); } /* printf( "\nEnter a line of words in single quotes - \'word1\'\n" ); scanf( " \'" ); if ( (scanf( "%[^\']", str) ) == 1 ) { printf( "<%s>\n", str ); } fflush( stdin ); printf( "\nEnter words delimited by regular punctuation\n" ); while ( (scanf( " %[^ ?;-,.\n]%*c", str) ) >= 1 ) { printf( "(%s)\n", str ); } printf( "\nEnter a series of characters\n" ); while ( (scanf( "%c", &c1) ) != EOF ) { printf( ( (c1 < ' ') ? "<%#.2x>" : "<%c>" ), c1 ); } printf( "\n" ); */ return( 0 ); }