LEC20081127 - Introduction to Computer Programming November...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to Computer Programming November 27, 2008 CSC180 Fall 2008, University of Toronto Modules and interfaces A module is a collection of functions. For example, stack.c is a module. /* stack.c */ #include <stdio.h> #include "stack.h" #if MAXVAL < 100 || MAXVAL % 10 != 0 #error MAXVAL must be at least 100 and a multiple of 10. #endif static int sp = 0; /* next free stack position */ static double val[MAXVAL]; /* value stack */ /* push f onto value stack */ CSC180 Fall 2008, University of Toronto 1 void push(double f) { if (sp < MAXVAL) val[sp++] = f; else printf("error: stack full, cant push %g\n", f); } /* pop and return top value from stack */ double pop(void) { if (sp > 0) return val[--sp]; else { printf("error: stack empty"); return 0.0; } } An interface describes available functions. For example, stack.h is an interface. Each library header file is an interface. CSC180 Fall 2008, University of Toronto 2 /* stack.h */ #ifndef STACK_H #define STACK_H #define MAXVAL 100 /* max depth of val stack */ void push(double); double pop(void);...
View Full Document

Page1 / 12

LEC20081127 - Introduction to Computer Programming November...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online