SEEM 3460 Tutorial Multimodule programming in C SEEM

  • Slides: 11
Download presentation
SEEM 3460 Tutorial Multi-module programming in C

SEEM 3460 Tutorial Multi-module programming in C

SEEM 3460 Tutorial Multi-module programming in C Before we start: 1. 2. Please log

SEEM 3460 Tutorial Multi-module programming in C Before we start: 1. 2. Please log on to the server Please recall how to edit text files on Linux/Unix

Copy the material n Create the directory n mkdir c_multi cd c_multi mkdir ask

Copy the material n Create the directory n mkdir c_multi cd c_multi mkdir ask n cd ask n n n Copy files n n cp ~seem 3460/distribute/c_multi-module/ask_reverse. c cp ~seem 3460/distribute/c_multi-module/ask_palindrome. c

Framework 1 reverse. o palindrome. o ask_palindrome (place to start) ask_reverse

Framework 1 reverse. o palindrome. o ask_palindrome (place to start) ask_reverse

Target Structure palindrome. h c ask_palindrome. c (place to start) reverse. h c ask_reverse.

Target Structure palindrome. h c ask_palindrome. c (place to start) reverse. h c ask_reverse. c

Modularizing Reverse reverse. c #include <string. h> #include “reverse. h” void reverse(. . .

Modularizing Reverse reverse. c #include <string. h> #include “reverse. h” void reverse(. . . ) {. . . } reverse. h ask_reverse. c void reverse(. . . ); #include <stdio. h> #include <string. h> #include “reverse. h” int main() {. . . } void reverse(. . . ) {. . . }

Modularizing Reverse n Create “reverse. h” and “reverse. c” n How to paste under

Modularizing Reverse n Create “reverse. h” and “reverse. c” n How to paste under unix: n n With the help of copy and paste n n Shift+insert, right click (not in x-win 32) >cp ask_reverse. c >cp reverse. c reverse. h Edit “reverse. c” and “reverse. h” Edit “ask_reverse. c”

Compile n Create. o files: n n n gcc -c reverse. c gcc -c

Compile n Create. o files: n n n gcc -c reverse. c gcc -c ask_reverse. c Link. o files as executables: n gcc -o ask_reverse. o

Modularizing palindrome. c palindrome. h ask_palindrome. c #include <string. h> #include “palindrome. h” int

Modularizing palindrome. c palindrome. h ask_palindrome. c #include <string. h> #include “palindrome. h” int palindrome(. . . ); #include <stdio. h> #include <string. h> #include “palindrome. h” #include “reverse. h” int palindrome(. . . ) {. . . } void reverse(. . . ) {. . . } int main(. . . ) {. . . }

Compile n Create. o files: n n n gcc -c palindrome. c gcc -c

Compile n Create. o files: n n n gcc -c palindrome. c gcc -c ask_palindrome. c Link. o files as executables: n gcc -o ask_palindrome. o reverse. o

Framework 2 (for your interest) rectangle. o replace. o print_rect. o area_rect. o label_rect

Framework 2 (for your interest) rectangle. o replace. o print_rect. o area_rect. o label_rect (place to start) cp ~seem 3460/distribute/c_multi-module/label_rect. c