Skip to content

Instantly share code, notes, and snippets.

@JimmyJames404
Created October 18, 2021 18:48
Show Gist options
  • Save JimmyJames404/339444342ef5ab286a29427098c16fa1 to your computer and use it in GitHub Desktop.
Save JimmyJames404/339444342ef5ab286a29427098c16fa1 to your computer and use it in GitHub Desktop.

Compiling Programs


Now, before we can execute the hello.c program, recall that we must compile it with a compiler, translating it from source code into machine code (i.e., zeroes and ones). Execute the command below to do just that:

make hello

And then execute this one again:

 ls

This time, you should see not only hello.c but hello listed as well? You’ve now translated the source code in hello.c into machine code in hello.

Now execute the program itself by executing the below.

./hello

Hello, world, indeed!

Getting User Input


Suffice it to say, no matter how you compile or execute this program, it only ever prints hello, world. Let’s personalize it a bit, just as we did in class.

Modify this program in such a way that it first prompts the user for their name and then prints hello, so-and-so, where so-and-so is their actual name.

As before, be sure to compile your program with:

make hello

And be sure to execute your program, testing it a few times with different inputs, with:

./hello

How to Test Your Code


Execute the below to evaluate the correctness of your code using check50. But be sure to compile and test it yourself as well!

check50 cs50/problems/2021/x/hello

Execute the below to evaluate the style of your code using style50.

style50 hello.c

How to Submit

Execute the below to submit your work.

submit50 cs50/problems/2021/x/hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment