#include #include #include inline int read_number(char *q, int &p) { int n = 0 ; while (isdigit(q[p])) { n = 10*n + (int) q[p] - (int) '0' ; ++p ; } return n ; } inline void skip_blanks(char *q, int &p) { while (q[p] && q[p] == ' ') ++p ; } // returns 0 on success, 1 on failure int parseNumbers(char *q, int &num1, int &num2) { int ret1, ret2 ; int p = 0 ; // Just doing it a very simple way // read in the first number if (!isdigit(q[p])) return 1 ; ret1 = read_number(q, p) ; // read in plus sign if (q[p] != '+') return 1 ; ++p ; // read in the second number if (!isdigit(q[p])) return 1 ; ret2 = read_number(q, p) ; // be sure we're at the end if (q[p] != '\0') return 1 ; num1 = ret1 ; num2 = ret2 ; return 0 ; } void printErrorMessage(char *M) { cout << "Content-type: text/html" << endl << endl << "" << endl << "Unable to process request" << endl << "" << endl << "

Unable to process request

" << endl << "

Unable to process form because " << M << "

" << endl << "" << endl << "" << endl ; } void printSuccess(int num1, int num2) { // You better put some code in here } void main(int argc, char *argv[]) { char *qs ; qs = getenv("QUERY_STRING") ; if (qs ==(char *)NULL) { printErrorMessage("no query string") ; } else { int n1, n2 ; if (parseNumbers(qs, n1, n2)) { printErrorMessage("bad query string") ; } else { printSuccess(n1, n2) ; } } }