Scholarly Resources for CompSci Undergrads

C Programming Language

Notes about C Debugging (slides 4 and 5)

Back to Introduction down to slide 4 down to slide 5 Forward to A Longer Example


Slide 4: Short Example (main.h)


main.h

#include <stdio.h>
  int fclose(FILE *stream);
  int fprintf(FILE *stream, const char *format,...);

  /* [On the system we used in 1994, it was unfortunately sometimes 
      necessary to explicitly declare library prototypes. -- 19 May 1996] */

typedef char *             string;
typedef short unsigned int bool;

#define TRUE  (1)
#define FALSE (0)

/* util.c prototypes */
void usage(const string name);
string basename(string command);
bool close_file(const string name,  const string proc, \
                const string fname, FILE * handle);
FILE * open_file(const string name,  const string proc, \
                 const string fname, const string mode);
/* Before you comment on my use of `const string' please read the errors section of the introduction */

Slide 5: Short Example (util.c)


util.c

#include "main.h"

static int open_files = 0; /* number of files currently open */

   .
   .
   .

bool close_file(const string progname, /* name of the program       */
                const string proc,     /* name of function calling  */
                const string fname,    /* filename of file to close */
                      FILE * handle)   /* the file to be closed     */
{
   if (fclose(handle) == EOF) {
      fprintf(stderr, "%s[%s()] Error: cannot close file `%s'\n",
              name, proc, fname);
      return(FALSE);
   } else {
      open_files--; 
#     if DEBUG > 1
         fprintf(stderr,"%s() closed %s\n", proc, fname);
#     endif
      return(TRUE);
   }
} /* close_file() */

Where to next?

These slides

back up to Slide 4 back up to Slide 5

Other slides

Back to Introduction Up to List of Contents Forward to a longer example


http://www.csd.uwo.ca/~jamie/C/Debug/short_example.html>

Last updated by J. Blustein on 28 May 1996.

This document is copyright by its author, J. Blustein <jamie@csd.uwo.ca>.

HTML 2.0 Checked!