CSC195, Class 33: Notes on Exam 1 Overview: * General issues * Problems with strings * The readLine procedure + Specification + Testing + Implementation Notes: * I hope you had a great break * Peanut Chews * Exam 1 returned * Don't forget to read Gries for tomorrow. * Meet in Saints Rest some time next week? About the exam. * Lots and lots of notes available online * General issues: + Cite like you'd cite any reference material (author, title, etc.) + What should you do when something goes wrong? (E.g., rdln encounters EOF before it's supposed to.) + printf("Encountered unexpected EOF"); You don't want to print too much output. Gives the dreaded "Why am I getting this error" problem. + Ignore it completely. It might not be a big deal We have preconditions for a reason; it takes extra code to check for errors occuring + Return a special failure value. Better than ignoring it completely; the caller now knows something has gone wrong. + Use exceptions to indicate an error (not in C) + Sam is very precise about the six P's. /* * Procedure: * name-of-procedure * Parameters: * foo, type * bar, type * Purpose: */ + Sam hates if (test) return 1; else return 0; + Sam also hates (if test #t #f) ; Scheme + Sam would prefer return test; ---------------------------------------- Some interesting decisions related to strings char *str; strncpy(str, "hello", 6); Need to actually have space to point to. char str[6]; strncpy(str, "hello", strlen(str)); Better strncpy(str, "hello", sizeof(str)); ---------------------------------------- Back to readLine