%{ #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 ansa = 0, ansb = 0, ansc = 0, ansd = 0 , anse = 0 ; int correct = 1 ; %} WS [ \t] %% "answer6-3a=T"\&? { ansa = 1 ; } "answer6-3b=T"\&? { ansb = 1 ; } "answer6-3c=T"\&? { ansc = 1 ; } "answer6-3d=T"\&? { ansd = 1 ; } "answer6-3e=T"\&? { anse = 1 ; } \n {} %% #include main() { yylex() ; } yywrap() { if( ansa && !ansb && !ansc && ansd && !anse ) send_file( "ans6-3.right" ) ; else { printf( "Content-type: text/html\n\n" ) ; printf( "\n\n" ) ; printf( "Experimental C Tutorial - Part 6-3\n" ) ; printf( "\n\n" ) ; printf( "

Sorry, you answered one or more incorrectly

\n" ) ; if( !ansa ) { printf( "It is valid to take the address of a character\n" ) ; printf( "and put it into a pointer to a character.\n" ) ; } if( ansb ) { printf( "

Since p and q are pointers to different types of\n" ) ; printf( "data we can't assign from one to the other wtih\n" ) ; printf( "assurance that it will be meaningful. The compiler\n" ) ; printf( "recognizes that sometimes this might be what we\n" ) ; printf( "really want, so it just issues a warning.\n" ) ; } if( ansc ) { printf( "

If we want q to point to x, we need to set it\n" ) ; printf( "to the address of x, not to the value of x.\n" ) ; } if( !ansd ) { printf( "

Using malloc in this way is the correct way\n" ) ; printf( "to allocate 100 integers as the program runs\n" ) ; printf( "(as opposed to at the time the program is compiled\n" ) ; printf( "which is what an array does).\n" ) ; } if( anse ) { printf( "

If we want p to point to c, we need to set it\n" ) ; printf( "to the address of c, not to the value of c.\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 ) ; } }