Outline for May 29, 2002

Handouts: Homework 5

Reading: Johnsonbaugh and Kalin, pp. 679-702 (appendix of useful functions)


  1. Greetings and felicitations!
  2. Standard I/O Library (#include <stdio.h>)
  3. a. open file: fopen
  4. b. unstructured read/write: getchar, fgetc (getc), putchar, fputc (putc)
  5. c. formatted read/write: fgets (gets), fscanf, fputs (puts), fprintf
  6. d. structured read/write: fread, fwrite
  7. e. random access: fseek, ftell, rewind
  8. f. close file: fclose
  9. g. miscellaneous: feof, ferror, clearerr
  10. Character types and conversions (#include <ctype.h>)
  11. a. alphabetics, numerics, alphanumerics: isalnum, ialdigit, isxdigit, isalpha
  12. b. upper, lower, and conversions: isupper, islower, toupper, tolower
  13. c. types of chars: iscntrl, isgraph (not blank, printable), isprint (printable), ispunct, isspace
  14. String conversion (#include <stdlib.h>)
  15. a. string to number: atoi, atof, atol
  16. String functions (#include <string.h>)
  17. a. compare: strcmp, strncmp, strcasecmp, strncasecmp; memcmp
  18. b. copy: strcpy, strncpy; memcpy (no overlap), memmove (overlap okay)
  19. c. find character: strchr (index), strrchr (rindex), strpbrk; memchr
  20. d. length: strlen
  21. Memory management (#include <stdlib.h>
  22. a. Allocation: malloc, calloc
  23. b. Release: free, cfree (deprecated)
  24. c. Reallocation: realloc()
  25. Miscellaneous
  26. a. terminate program (exit); include <stdlib.h>
  27. b. sort array of data (qsort); include <stdlib.h>
  28. c. time of day (time, ctime); include <time.h>
  29. d. execute cvommand (system); include <stdlib.h>
  30. Debugging
  31. a. programs have bugs; find and fix them
  32. b. static debugging: insert debugging code into source, recompile and run
  33. c. dynamic debugging: look at the program as it runs, observing (and maybe changing) variables, etc.
  34. Static debugging
  35. a. using printf to print variable values; mention %p (prints pointer value, usually as a hex integer)
  36. b. using printf to print where you are (ie, on function entry printf("in function\n");
  37. c. #ifdef DEBUG ... #endif around the printfs so you can leave them in the source if you need them again
  38. d. assert(x) macro: assert(0 <= i && i <= n) causes program to exit with error message if (0 <= I && I <= n) is false; must include <assert.h>. To delete, say #define NDEBUG and they will not be in the compiled code.
  39. Dynamic debugging
  40. a. debugging tool instruments executable program so it can be stopped, examined, altered, and continued interactively
  41. b. go through the handout
  42. c. mention the "where" command which shows you the program stack

ECS 30-A, Introduction to Programming
Spring Quarter 2002
Email: [email protected]