/* freq_alp.c -- order frequencies alphabetically */ #include #include #include "ios.h" /* using the input/output service module */ #define ERR_LINE 1 #define ERR_REPEAT 2 static long int Table [256]; void main ( int argc, char * argv [] ) { int c, n; long int N; char cc; char * from; FILE * outfile; if ( argc < 4 ) err_command_line ( "freq_alp alphabet infile outfile" ); open_input_file ( argv [2] ); for ( c=0; c<256; c++ ) Table [c] = 0; while ( 0 <= get_line ( & from ) ) { if ( 2 != sscanf ( from, " %c %ld", &cc, &N ) ) { printf ( "wrong input line [%s]\n", from ); exit ( ERR_LINE ); } c = (unsigned char) cc; if ( Table [c] ) { printf ( "repeated letter: [%s]\n", from ); exit ( ERR_REPEAT ); } Table [c] = N; } open_input_file ( argv [1] ); n = get_line_sure ( & from ); outfile = open_output_file ( argv [3] ); while ( --n >= 0 ) { c = (unsigned char) *from++ ; if ( ( c & 0x80 ) || ! isascii (c) || ! isspace (c) ) fprintf ( outfile, "[ %c %ld ]\n", c, Table [c] ); } exit (0); } /* end of freq_alp.c */