#include #include #include #include #include // The following *must* be a full path name // This is where you store the number #define STATEFILE "/usr/users/XXXXX/home05.dat" 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 parseNumber(char *q, int &num) { int ret ; int p = 0 ; // Just doing it a very simple way // read in plus sign if (q[p] != '+') return 1 ; ++p ; // read in the number if (!isdigit(q[p])) return 1 ; ret = read_number(q, p) ; // be sure we're at the end if (q[p] != '\0') return 1 ; num = ret ; 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 cookie, int adden, int newCookie) { // you fill in here } void main(int argc, char *argv[]) { char *qs ; int addNum ; qs = getenv("QUERY_STRING") ; if (qs ==(char *)NULL) printErrorMessage("no query string") ; else if (parseNumber(qs, addNum)) printErrorMessage("bad query string") ; else { int oldNum, newNum ; // There is where you read, update, and then write the number printSuccess(oldNUm, addNum, newNum) ; } }