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

Sorry, you answered one or more incorrectly

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

Remember that scanf with a\n" ) ; printf( "%%s expects an array as the next argument.\n" ) ; printf( "and since name is the name of\n" ) ; printf( "an array, scanf( \"%%s\", name );\n" ) ; printf( "is indeed valid.\n" ) ; } if( ans5b ) { printf( "

scanf with a %s format specifier\n" ) ; printf( "expects an array as the next argument. However\n" ) ; printf( "since name is already an array, we don't\n" ) ; printf( "want the ampersand (&) before it.\n" ) ; } if( !ans5c ) { printf( "

Since name is an array of characters,\n" ) ; printf( "name[x] is a character. So it's quite\n" ) ; printf( "legal to assign a character constant to it.\n" ) ; } if( !ans5d ) { printf( "

Since name is an array of characters,\n" ) ; printf( "name[x] is a character. So it's quit\n" ) ; printf( "legal to assign a character constant to it.\n" ) ; printf( "Also remember that \\n is a valid character.\n" ) ; } if( ans5e ) { printf( "

While we might expect that we could set the\n" ) ; printf( "value of a string by assigning a literal string\n" ) ; printf( "to it, for various reasons, C does not support\n" ) ; printf( "that operation. As we'll see, there is a standard\n" ) ; printf( "function for copying strings.\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 ) ; } }