{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

to fix them now take a look at findc with nano notice

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: built by invoking the second line’s command. Moreover, that first line tells make that generate is dependent on generate.c, the implication of which is that make will only re ­build generate on subsequent runs if that file was modified since make last built generate. Neat time ­saving trick, eh? In fact, go ahead and execute the command below again, assuming you haven’t modified generate.c. make generate 4 < 13 This is CS50. Harvard College Fall 2010 You should be informed that generate is already up to date. Incidentally, know that the leading whitespace on that second line is not a sequence of spaces but, rather, a tab. Unfortunately, make requires that commands be preceded by tabs, so be careful not to change them to spaces with Nano (which automatically converts tabs to four spaces), else you may encounter strange errors! The -Werror flag, recall, tells gcc to treat warnings (bad) as though they’re errors (worse) so that you’re forced (in a good, instructive way!) to fix them. Now take a look at find.c with Nano. Notice that this program expects a single command ­line argument: a “needle” to search for in a “haystack” of values. Once done looking over the code, go ahead and compile the program by executing the command below. make find Notice, per that command’s output, that Make actually executed the below for you. gcc -ggdb -std=c99 -Wall -Werror -Wformat=0 -o find find.c helpers.c -lcs50 -lm Notice further that you just compiled a program comprising not one but two .c files: helpers.c and find.c. How did make know what to do? Well, again, open up Makefile to see the man behind the curtain. The relevant lines appear below. find: find.c helpers.c helpers.h gcc -ggdb -std=c99 -Wall -Werror -Wformat=0 -o find find.c helpers.c -lcs50 -lm Per the dependencies implied above (after the colon), any changes to find.c, helpers.c, or helpers.h will compel make to rebuild find the next time it’s invoked for this target. Go ahead and run this program by executing, say, the below. ./find 13 You’ll be prompted to provide some hay (i.e., some integers), one “straw” at a time. As soon as you tire of providing integers, hit ctrl ­d to send the program an EOF (end ­of ­file) character. That character will compel GetInt from the CS50 Library to retur...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online