/* restrict.c -- skip restriction (corrected formulas) */ #include #include #include #include "ios.h" /* using the input/output service module */ #define DESIRED 10.0 #define ERR_LINE 1 #define ERR_REPEAT 2 static long int Table [256]; static long int Total; void calculation ( double n, double L, double prob, double desired, int * restricted, long int * restriction, double * expected ); void main ( int argc, char * argv [] ) { int c, k, n; char cc; long int N; char * from; FILE * outfile; double prob, expected; long int restriction; int restricted; if ( argc < 4 ) err_command_line ( "restrict frequencies words outfile" ); open_input_file ( argv [1] ); for ( c=0; c<256; c++ ) Table [c] = 0; Total = 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; Total += N; } open_input_file ( argv [2] ); outfile = open_output_file ( argv [3] ); while ( 0 <= ( n = get_line ( & from ) ) ) { while ( n > 0 ) { c = (unsigned char) *from; if ( ( c & 0x80 ) || ! isascii (c) || ! isspace (c) ) break; ++ from; -- n; } while ( n > 0 ) { c = (unsigned char) from [n-1]; if ( ( c & 0x80 ) || ! isascii (c) || ! isspace (c) ) break; -- n; } if ( n < 2 ) { printf ( "warning: word [ %s ] is too short\n", from ); continue; } prob = 1.0; for ( k=0; k floor ( L / n1 ) ) D = floor ( L / n1 ); * restriction = (long int) D; * expected = prob * 2.0 * ( D - 1.0 ) * ( L - n1 * ( 2.0 + D ) * 0.5 ); } /* end of restrict.c */