Httpwwwcs50netresourcescppreferencecomstdotherrandhtml

Info icon This 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: m number generator’s initial seed. 3 < 13 This is CS50. Harvard College Fall 2010 Now take a look at generate.c itself with Nano. (Remember how?) Comments atop that file explain the program’s overall functionality. But it looks like we forgot to comment the code itself. Read over the code carefully until you understand each line and then comment our code for us, replacing each TODO with a phrase that describes the purpose or functionality of the corresponding line(s) of code. Realize that a comment flanked with /* and */ can span lines whereas a comment preceded by // can only extend to the end of a line; the latter is a feature of C99 (the version of C that we’ve been using). If Problem Set 1 feels like a long time ago, you might want to read up on rand and srand again at the URLs below. http://www.cs50.net/resources/cppreference.com/stdother/rand.html http://www.cs50.net/resources/cppreference.com/stdother/srand.html Or you can execute the commands below. man rand man srand Once done commenting generate.c, re ­compile the program to be sure you didn’t break anything by re ­executing the command below. make generate If generate no longer compiles properly, take a moment to fix what you broke! Now, recall that make automates compilation of your code so that you don’t have to execute gcc manually along with a whole bunch of switches. Notice, in fact, how make just executed a pretty long command for you, per the tool’s output. However, as your programs grow in size, make won’t be able to infer from context anymore how to compile your code; you’ll need to start telling make how to compile your program, particularly when they involve multiple source (i.e., .c) files. And so we’ll start relying on “Makefiles,” configuration files that tell make exactly what to do. How did make know how to compile generate in this case? It actually used a configuration file that we wrote. Using Nano, go ahead and look at the file called Makefile that’s in the same directory as generate.c. This Makefile is essentially a list of rules that we wrote for you that tells make how to build generate from generate.c for you. The relevant lines appear below. generate: generate.c gcc -ggdb -std=c99 -Wall -Werror -Wformat=0 -o generate generate.c The first line tells make that the “target” called generate should be...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern