1
COMP 1402
Winter 2008 Tutorial #3
Overview of Tutorial #3
- Review of Number Representation
- Creating Archives (TAR utility)
- Compling C Programs
- Creating Makefiles
- Emacs text editor
COMP 1402 Winter 2008 Tutorial #3 Overview of Tutorial #3 Review - - PDF document
COMP 1402 Winter 2008 Tutorial #3 Overview of Tutorial #3 Review of Number Representation Creating Archives (TAR utility) Compling C Programs Creating Makefiles Emacs text editor 1 Review of Number Representation
– tar –xvf archive.tar
– x – extract – v – verbose (have tar tell you what it is doing) – f – file, tells tar the the next item is the file to execute the command on.
Header file: max.h Source file: max.c #include "max.h" int max(int a, int b) { if(a > b) { return a; } else { return b; } } #ifndef MAX_H #define MAX_H int max(int a, int b); #endif Don’t worry about the #ifndef, #define, #endif lines for now – the header simply declares the function max() The source file provides an implementation (or definition) of the function max().
#include <stdio.h> #include "max.h" int main(int argc, char *argv[]) { int a, b; printf("Enter a number.\n"); scanf("%d",&a); printf("Enter a number.\n"); scanf("%d",&b); printf("%d is bigger.\n", max(a,b) ); } #include "max.h" int max(int a, int b) { if( a > b) { return a; } else { return b; } }
File max.c File main.c
#Comments proceeded by hash symbol target1: dependencies compilation commands target2: dependencies compilation commands
#My first Makefile helloworld: helloworld.c gcc –o helloworld helloworld.c
“helloworld.c”.
– gcc –o helloworld helloworld.c
File: Makefile
#My first Makefile main: main.c helper1.o helper2.o gcc –o main main.c helper1.o helper2.o helper1.o: helper1.c helper1.h gcc –o helper1.o –c helper1.c helper2.o: helper2.c helper2.h gcc –o helper2.o –c helper2.c
#My first Makefile main: main.c helper1.o helper2.o gcc –o main main.c helper1.o helper2.o helper1.o: helper1.c helper1.h gcc –o helper1.o –c helper1.c helper2.o: helper2.c helper2.h gcc –o helper2.o –c helper2.c
#My first Makefile helloworld: helloworld.c gcc –o helloworld helloworld.c
then the command: gcc –o helloworld helloworld.c is executed.