%{ #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 ans4a = 0, ans4b = 0, ans4c = 0, ans4d = 0 , ans4e = 0 ; int correct = 1 ; %} WS [ \t] %% "answer1-4a=T"\&? { ans4a = 1 ; } "answer1-4b=T"\&? { ans4b = 1 ; } "answer1-4c=T"\&? { ans4c = 1 ; } "answer1-4d=T"\&? { ans4d = 1 ; } "answer1-4e=T"\&? { ans4e = 1 ; } \n {} %% #include main() { yylex() ; } yywrap() { if( ans4a && !ans4b && !ans4c && ans4d && ans4e ) send_file( "ans1-4.right" ) ; else { printf( "Content-type: text/html\n\n" ) ; printf( "\n\n" ) ; printf( "Experimental C Tutorial - Part 1-4\n" ) ; printf( "\n\n" ) ; printf( "

Sorry, you answered one or more incorrectly

\n" ) ; if( !ans4a ) { printf( "

int is a valid variable type and num_stud\n" ) ; printf( "satisfies all the requirement for a C variable.\n" ) ; } if( ans4b ) { printf( "

If the author had meant to have a variable called\n" ) ; printf( "num students, then that would violate C's rules which\n" ) ; printf( "dont' allow a space in the variable name. If the\n" ) ; printf( "author had meant to declare two variable, one called\n" ) ; printf( "num and the other called students, then a comma\n" ) ; printf( "separating them was left out.\n" ) ; } if( ans4c ) { printf( "

The correct type for an integer variable is int\n" ) ; printf( "and variable names may not begin with a digit.\n" ) ; } if( !ans4d ) { printf( "

float is a valid type and five_options and\n" ) ; printf( "IsStudent both satisfy the\n" ) ; printf( "characteristics of valid C variables.\n" ) ; } if( !ans4e ) { printf( "

char is a valid type and position_5 is a valid\n" ) ; printf( "variable name.\n" ) ; } printf( "

Return and try again\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 ) ; } }