%{ #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 ans5a = 0, ans5b = 0, ans5c = 0, ans5d = 0 , ans5e = 0 ; int correct = 1 ; %} WS [ \t] %% "answer2-5a=T"\&? { ans5a = 1 ; } "answer2-5b=T"\&? { ans5b = 1 ; } "answer2-5c=T"\&? { ans5c = 1 ; } "answer2-5d=T"\&? { ans5d = 1 ; } "answer2-5e=T"\&? { ans5e = 1 ; } \n {} %% #include main() { yylex() ; } yywrap() { if( !ans5a && ans5b && ans5c && ans5d && !ans5e ) send_file( "ans2-5.right" ) ; else { printf( "Content-type: text/html\n\n" ) ; printf( "\n\n" ) ; printf( "Experimental C Tutorial - Part 2-5\n" ) ; printf( "\n\n" ) ; printf( "

Sorry, you answered one or more incorrectly

\n" ) ; if( ans5a ) { printf( "void is a type that replaces the\n" ) ; printf( "entire argument list. Individual\n" ) ; printf( "parameters are not of type void.\n

\n" ) ; } if( !ans5b ) { printf( "It is perfectly legal to have a type with no\n" ) ; printf( "parameter name in a prototype, but not in the\n" ) ; printf( "real function declaration. It is also allowable\n" ) ; printf( "for a function to return a type different from\n" ) ; printf( "parameters.\n

\n" ) ; } if( !ans5c ) { printf( "A function may have several parameters of\n" ) ; printf( "different types and it may return a value of\n" ) ; printf( "a type different from all its parameters.\n

\n" ) ; } if( !ans5d ) { printf( "While it's not likely to be doing much in the\n" ) ; printf( "context of the rest of the program, there's\n" ) ; printf( "nothing to prevent us from having a function that\n" ) ; printf( "takes no paramters and doesn't return\n" ) ; printf( "anything.\n

\n" ) ; } if( ans5e ) { printf( "While it might seem reasonable for you to\n" ) ; printf( "declare multiple parameters of the same type by\n" ) ; printf( "listing the type only once, C doesn't allow this.\n" ) ; printf( "Even if they are of the same type, multiple\n" ) ; printf( "parameters must each have a type given.\n

\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 ) ; } }