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

Sorry, you answered one or more incorrectly

\n" ) ; if( !ans5a ) { printf( "student_body is an array of structures, so\n" ) ; printf( "student_body[i] is a structure. One member of\n" ) ; printf( "the structure is gpa which is a float.\n" ) ; } if( ans5b ) { printf( "

student_body is an array of structures, so\n" ) ; printf( "student_body[i] is a structure. Since it is\n" ) ; printf( "a structure and not a pointer, the operator ->\n" ) ; printf( "is not valid with it's left operand.\n" ) ; } if( !ans5c ) { printf( "

this_student is a pointer to a structure and\n" ) ; printf( "gpa is a floating point member of that structure\n" ) ; printf( "so this_student->gpa is a valid floating point\n" ) ; printf( "expression.\n" ) ; } if( ans5d ) { printf( "

Since this_student->gpa is a floating point\n" ) ; printf( "&this_student->gpa is a pointer to a float - not\n" ) ; printf( "a float itself. This is because the -> operator\n" ) ; printf( "has higher precedence than the & operator.\n" ) ; } if( !ans5e ) { printf( "

Since this_student is a pointer to a structure\n" ) ; printf( "(*this_student) is the structure it point to. So\n" ) ; printf( "since gpa is a floating point member of that\n" ) ; printf( "structure, (*this_student).gpa is a float.\n" ) ; } if( ans5f) { printf( "

Since this_student is a pointer to a structure\n" ) ; printf( "(*this_student) is the structure it point to. So\n" ) ; printf( "the -> operator does not have a pointer on the left\n" ) ; printf( "and is invalid in this context.\n" ) ; } if( ans5g ) { printf( "

this_student is a pointer to a structure and the\n" ) ; printf( "dot (.) operator expects a structure on the left\n" ) ; printf( "so the dot is invalid in this context.\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 ) ; } }