#include #include #include #include "stdio.h" #include "stdlib.h" extern "C" char *getenv(const char *name); main( ) { cout << "Content-type: text/html" << char(10) << char(10); String com = getenv("QUERY_STRING"); char c; int count = 0; String my_address = "/Net/mathstat/Users/Fac1/djaffe"; if ( com.length( ) < 3 || com[0] != 'n' || com[1] != '=' || !com.contains("&k=") ) { cout << "Illegal request."; exit(0); } String html1_addr = my_address + "/Library/Public_html/codes/codeform.html1"; FILE *html1; html1 = fopen( (&(html1_addr[0])), "r" ); while( (c=getc(html1)) != EOF ) cout << c; fclose(html1); com.del( "n=" ); String ns = com.before("&k="); String ks = com.after("&k="); int n = int( atoI(ns).as_long( ) ); int k = int( atoI(ks).as_long( ) ); cout << "Answer when n = " << n << " and k = " << k << ":\n"; cout << "

\n"; String nkfile = my_address + "/Library/Public_html/binary/" + dec(n) + "/" + dec(k) + "/@main"; FILE *fp; FILE *html2; if ( n <= 0 ) { cout << "Your value for n must be at least 1.\n"; goto tail; } if ( k <= 0 || k >= n ) { cout << "Your value for k must be between 1 and n-1.\n"; goto tail; } fp=fopen((&(nkfile[0])), "r"); if ( fp == 0 ) { cout << "I'm sorry, but I have no information for codes with " << "n = " << n << " and k = " << k << ".\n"; goto tail; } while( (c=getc(fp)) != EOF ) { cout << c; count++; if ( c == '\n' || c == ' ' ) count = 0; if ( count >= 80 && c == ',' ) { count = 0; cout << "\n"; } } fclose(fp); tail: cout << "


\n"; String html2_addr = my_address + "/Library/Public_html/codes/codeform.html2"; html2 = fopen( (&(html2_addr[0])), "r" ); while( (c=getc(html2)) != EOF ) cout << c; fclose(html2); }