Outline for May 24, 2002

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

  1. Greetings and felicitations!
  2. Libraries
    1. compiling with libraries
    2. common libraries: stdio, ctype
  3. Standard I/O Library (#include <stdio.h>)
    1. open file: fopen
    2. unstructured read/write: getchar, fgetc (getc), putchar, fputc (putc)
    3. formatted read/write: fgets (gets), fscanf, fputs (puts), fprintf
    4. structured read/write: fread, fwrite
    5. random access: fseek, ftell, rewind
    6. close file: fclose
    7. miscellaneous: feof, ferror, clearerr
  4. Character types and conversions (#include <ctype.h>)
    1. alphabetics, numerics, alphanumerics: isalnum, ialdigit, isxdigit, isalpha
    2. upper, lower, and conversions: isupper, islower, toupper, tolower
    3. types of chars: iscntrl, isgraph (not blank, printable), isprint (printable), ispunct, isspace
  5. String conversion (#include <stdlib.h>)
    1. string to number: atoi, atof, atol
  6. String functions (#include <string.h>)
    1. compare: strcmp, strncmp, strcasecmp, strncasecmp; memcmp
    2. copy: strcpy, strncpy; memcpy (no overlap), memmove (overlap okay)
    3. find character: strchr (index), strrchr (rindex), strpbrk; memchr
    4. length: strlen
  7. Memory management (#include <stdlib.h>
    1. Allocation: malloc, calloc
    2. Release: free, cfree (deprecated)
    3. Reallocation: realloc()
  8. Miscellaneous
    1. terminate program (exit); include <stdlib.h>
    2. sort array of data (qsort); include <stdlib.h>
    3. time of day (time, ctime); include <time.h>
    4. execute cvommand (system); include <stdlib.h>
  9. Debugging
    1. programs have bugs; find and fix them
    2. static debugging: insert debugging code into source, recompile and run
    3. dynamic debugging: look at the program as it runs, observing (and maybe changing) variables, etc.
  10. Static debugging
    1. using printf to print variable values; mention %p (prints pointer value, usually as a hex integer)
    2. using printf to print where you are (ie, on function entry printf("in function\n");
    3. #ifdef DEBUG ... #endif around the printfs so you can leave them in the source if you need them again
    4. 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.
  11. Dynamic debugging
    1. debugging tool instruments executable program so it can be stopped, examined, altered, and continued interactively
    2. go through the handout
    3. mention the "where" command which shows you the program stack

ECS 30-A, Introduction to Programming
Spring Quarter 2002
Email: cs30a@cs.ucdavis.edu