%{ #define YY_INPUT(buf,result,max_size) \ { int digit ; \ int c = getc( yyin ) ; \ result = c == EOF ? 0 : 1 ; \ if( c == '%' ) { \ c = getc( yyin ) ; \ digit = c >= 'A' ? (( c & 0xdf ) - 'A' ) + 10 : c - '0' ; \ digit *= 16 ; \ c = getc( yyin ) ; \ digit += c >= 'A' ? (( c & 0xdf ) - 'A' ) + 10 : c - '0' ; \ buf[0] = (char) digit ; \ } \ else if( c == '+' ) \ buf[0] = ' ' ; \ else \ buf[0] = (char) c ; \ } int ans1a = 0, ans1b = 0, ans1c = 0, ans1d = 0 , ans1e = 0 ; int correct = 1 ; %} WS [ \t] %% "answer7-1a=T"\&? { ans1a = 1 ; } "answer7-1b=T"\&? { ans1b = 1 ; } "answer7-1c=T"\&? { ans1c = 1 ; } "answer7-1d=T"\&? { ans1d = 1 ; } "answer7-1e=T"\&? { ans1e = 1 ; } \n {} %% #include main() { yylex() ; } yywrap() { if( ans1a && !ans1b && ans1c && !ans1d ) send_file( "ans7-1.right" ) ; else { printf( "Content-type: text/html\n\n" ) ; printf( "\n\n" ) ; printf( "Experimental C Tutorial - Part 7-1\n" ) ; printf( "\n\n" ) ; printf( "

Sorry, you answered one or more incorrectly

\n" ) ; if( !ans1a ) { printf( "Since the price of the car is naturally a number\n" ) ; printf( "we need to store both a string and a number for\n" ) ; printf( "each car and an array can't store both strings\n" ) ; printf( "and numbers at the same time\n" ) ; } if( ans1b ) { printf( "

Temperatures taken on a grid are each numbers.\n" ) ; printf( "Since we have a regular set of numbers divided into\n" ) ; printf( "rows and columns, a two-dimensional array is\n" ) ; printf( "natural for storing them.\n" ) ; } if( !ans1c ) { printf( "

Notice that we have a string and two numbers.\n" ) ; printf( "We can't store strings and numbers both in the\n" ) ; printf( "same array. So we need to use a record.\n" ) ; } if( ans1d ) { printf( "

Here each model name is a string and we have\n" ) ; printf( "many strings. We can store this naturally in an\n" ) ; printf( "array of strings (a two-dimensional array of\n" ) ; printf( "characters).\n" ) ; } printf( "

Return and try again\n" ) ; printf( "\n" ) ; } return( 1 ) ; } send_file( s ) char *s ; { FILE *fp ; char buf[81] ; printf( "Content-type: text/html\n\n" ) ; fp = fopen( s, "r" ) ; if( fp ) { while( fgets( buf, 80, fp )) { printf( "%s", buf ) ; } fclose( fp ) ; } }