109_pdfsam_cs2022

109_pdfsam_cs2022 - Multiple source files C lets you break...

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

View Full Document Right Arrow Icon
Multiple source files C lets you break up a program into several source files Unlike Java or Matlab, it doesn’t require you to do this How you break up the program is up to you To do this, Put the code for a function in exactly one file Put a function prototype in any file that uses the function
Background image of page 1

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

View Full Document Right Arrow Icon
Example: multiple source files #include <stdio.h> int power(int base, int exp); int cube(int base); int main(void) { printf(“%d\n”, power(5, 3)); printf(“%d\n”, cube(10)); return 0; } int power( int base, int exp ) { int i, p = 1; for( i = 1; i <= exp; i++ ) p *= base; return p; } int power(int base, int exp); int cube(int base) { return power(base, 3); } main.c power.c cube.c
Background image of page 2
Header files A C header file contains function prototypes But does not contain implementation code Files have extension .h by convention e.g. a snippet of stdio.h:n void perror(char *); int printf(char *, . ..); int putc(int, FILE *); int putchar(int); int puts(char *); int remove(char *); int rename (char *, char *); void rewind(FILE *); int scanf(char *, . ..);
Background image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 6

109_pdfsam_cs2022 - Multiple source files C lets you break...

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

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