Download presentation
Presentation is loading. Please wait.
Published byRodney Small Modified over 9 years ago
1
Announcements Assignment 1 will be regraded for all who’s score (not percentage) is less than 6 (out of 65). If your score is 6 or higher, but you feel there was a mistake, email your instructor (that’s me ) Let’s have NO formatting mistakes for Assignment 2! Make sure you name the files EXACTLY as in the specs. (remember Unix cares about case so isFib.c is NOT the same as isfib.c) Use the example programs and diff to make sure your program is correct. 1
2
What is “make”? make is a Unix tool that simplifies the task of compiling large and complex software projects – the programmer creates a Makefile that speficies: which files depend on which other files what commands to run when a file changes and needs to be (re)compiled – make reads Makefile and runs commands as necessary not such a big deal for small single-source-file programs very helpful when a large number of files involved can be used for many tasks that involve running some commands on files that have changed 2
3
Example Makefile mayan : mayan.c gcc –Wall mayan.c –o mayan What it means 1.The file mayan is built from the file mayan.c 2.To build mayan from mayan.c, execute this command 3
4
Makefile structure: rules Makefile mayan : mayan.c gcc –Wall mayan.c –o mayan 4 “target” file(s) the target depends on ( ≥ 0 ) (“prerequisites”) if any of these files is changed, the target must be recompiled. command ( ≥ 0 ) to execute if target is out of date w.r.t. the files it depends on “rule”
5
How make works Makefile target : prerequisite 1 … prerequisite n command 5 1.if target does not exist: – run command 2.else: if target is older than any of its prerequisites: – run command 3.else: /* (target is up to date) */ – do nothing Simplified Behavior of make
6
Example 6
7
Multiple Targets Makefile target1 : prerequisite 1 … prerequisite n command1 target2 : prerequisite 1 … prerequisite m command2 7 1.You can specify the target: make target2 2.If you don’t specify a target, the first target is used. Which target gets “made”
8
What can commands be? Makefile target : prerequisite 1 … prerequisite n ls -l 8 1.The command doesn't have to be gcc, it can be any Unix command. 2.Here there is a rather silly Makefile that runs ls -l when target doesn't exist or has date older than a prerequisite 3.Notice ls doesn't update target. What happens then if make is run twice in a row?
9
clean Makefile isFib: isFib.c gcc -Wall -o isFib isFib.c clean: rm -f isFib 9 1.Often a makefile will include a "clean" object to remove files associated with the project 2.Here typing make clean will cause the executable to be deleted. 3.Notice that if there is no file named "clean" in the current directory, the rm command will run everytime you type make clean
10
Characters and strings A character is of type char (signed or unsigned) – C99 provides support for “wide characters” strings : – an array of characters – terminated by a 0 character (“NUL” : written ‘\0’) – Not a predefined type in C; string operations are provided through libraries C arrays don’t do bound-checking – careless programming can give rise to memory-corruption errors 10
11
Example of string manipulation 11 declares an array of chars the input analog to printf: “read a value into str” (%s = “string”) print out a string (%s)
12
More strings… 12 waits for input (from stdin) typed in on keyboard: stdin program output (stdout) end-of-file indicated by typing Ctrl-D
13
More strings… 13 Oops! this means the program tried to access an illegal memory address
14
More detail So “strings” are arrays of characters (that end with a NULL (‘\0’)) But what is a character? A character is a byte of data. This can be viewed as a (small) number or as a symbol from the ASCII table. To specify a character in C use single quotes: char c; c = ‘b’; Let’s go to a terminal and experiment 14
15
So even though characters can be thought of as letters, digits, or symbols, you can also use addition, subtraction, multiplication, etc on them. You can also compare them: ‘A’ < ‘G’ evaluates to true. The uppercase letters and lower case letters run in a sequence. i.e.: ‘c’ + 1 == ‘d’ 15
16
How can we use this to write a test if a character c is a capitol letter? 16
17
How can we use this to write a test if a character c is a upper case letter? if (c >= ‘A’ && c <= ‘Z’) { // if c is an uppercase letter then we go here } Let’s go to the terminal and write a function to convert all the lowercase letters of a string to upper case. 17
18
The completed program 18
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.