Skip to content

Commit 3f5da5f

Browse files
committed
instructions
1 parent 5064998 commit 3f5da5f

File tree

1 file changed

+3
-126
lines changed

1 file changed

+3
-126
lines changed

hello/index.md

Lines changed: 3 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Hello, you!
22

3-
> Deze opdracht is niet bedoeld voor samenwerken, maar je hoeft 'm ook niet helemaal alleen te doen. Het doel is ervaring opdoen met technieken en daarom moet je alles zelf oefenen. Maar schroom niet hulp te vragen, en als het nodig is kan iemand het even voordoen. Als je naderhand maar zelf alle stappen doorlopen hebt.
4-
5-
Here's your first C program:
3+
This was first C program:
64

75
#include <stdio.h>
86

@@ -11,121 +9,12 @@ Here's your first C program:
119
printf("hello, world\n");
1210
}
1311

14-
You have seen it in lecture, and now you're ready to try running it yourself.
15-
16-
17-
## Dive into your development environment
18-
19-
### Instructions for Mac OS
20-
21-
Go to your Terminal. You should find that its "prompt" resembles the below.
22-
23-
jharvard@somewhere ~ %
24-
25-
Here on out, to execute (i.e., run) a command means to type it into a terminal window and then hit Enter. Commands are "case-sensitive," so be sure not to type in uppercase when you mean lowercase or vice versa.
26-
27-
Now execute
28-
29-
cd ~/Documents/Programming/
30-
31-
to move yourself into (i.e., open) that directory. Your prompt should now resemble the below.
32-
33-
jharvard@somewhere Programming %
34-
35-
If not, retrace your steps and see if you can determine where you went wrong.
36-
37-
Now, open Atom, point to the File menu and choose New. This will open a new editor with a blank "Untitled1" file in it. First thing to do is to give it a name and save it into your new directory. Press **CTRL-S** or **Cmd-S** to open the file dialog. For **Filename**, type `hello.c`. Then below, choose (click) the `Documents`, then the `Programming` folder that you just created and click on **Save**.
38-
39-
In your new file, type the C code for "Hello, World" as seen above. Save it once more.
40-
41-
### Instructions for Windows
42-
43-
Go to your Terminal. You should find that its "prompt" resembles the below.
44-
45-
jharvard@COMPUTER:~$
46-
47-
Here on out, to execute (i.e., run) a command means to type it into a terminal window and then hit Enter. Commands are "case-sensitive," so be sure not to type in uppercase when you mean lowercase or vice versa.
48-
49-
Now execute
50-
51-
cd /mnt/c/Users/<Windows User Name>/Documents/Programming/
52-
53-
to move yourself into (i.e., open) that directory. Your prompt should now resemble the below.
54-
55-
jharvard@COMPUTER:Programming$
56-
57-
If not, retrace your steps and see if you can determine where you went wrong.
58-
59-
Now, open Atom, point to the File menu and choose New. This will open a new editor with a blank "Untitled1" file in it. First thing to do is to give it a name and save it into your new directory. Press **CTRL-S** or **Cmd-S** to open the file dialog. For **Filename**, type `hello.c`. Then below, choose (click) the `Documents`, then the `Programming` folder that you just created and click on **Save**.
60-
61-
In your new file, type the C code for "Hello, World" as seen above. Save it once more.
62-
63-
64-
## Listing files
65-
66-
Next, type precisely the below (in lowercase), then hit Enter:
67-
68-
ls
69-
70-
You should see just `Makefile` and `hello.c`. That's because you've just listed the files in that same folder, this time using a command-line interface (CLI), using just your keyboard, rather than the graphical user interface (GUI) represented by that folder icon. In particular, you *executed* (i.e., ran) a command called `ls`, which is shorthand for "list." (It's such a frequently used command that its authors called it just `ls` to save keystrokes.) Make sense?
71-
72-
73-
## Compiling programs
74-
75-
Now, before we can execute the program at right, recall that we must *compile* it with a *compiler* (e.g., `clang`), translating it from *source code* into *machine code* (i.e., zeroes and ones). Execute the command below to do just that:
76-
77-
clang hello.c
78-
79-
And then execute this one again:
80-
81-
ls
82-
83-
This time, you should see not only `hello.c` but `a.out` listed as well? (You can see the same graphically if you click that folder icon again.) That's because `clang` has translated the source code in `hello.c` into machine code in `a.out`, which happens to stand for "assembler output," but more on that another time.
84-
85-
Now run the program by executing the below.
86-
87-
./a.out
88-
89-
Hello, world, indeed!
90-
91-
92-
## Naming programs
93-
94-
Now, `a.out` isn't the most user-friendly name for a program. Let's compile `hello.c` again, this time saving the machine code in a file called, more aptly, `hello`. Execute the below.
95-
96-
clang -o hello hello.c
97-
98-
Take care not to overlook any of those spaces therein! Then execute this one again:
99-
100-
ls
101-
102-
You should now see not only `hello.c` (and `a.out` from before) but also `hello` listed as well? That's because `-o` is a *command-line argument*, sometimes known as a *flag* or a *switch*, that tells `clang` to output (hence the `o`) a file called `hello`. Execute the below to try out the newly named program.
103-
104-
./hello
105-
106-
Hello there again!
107-
108-
109-
## Making things easier
110-
111-
Recall from lecture that we can automate the process of executing `clang`, letting `make` figure out how to do so for us, thereby saving us some keystrokes.
112-
113-
Now execute the below to compile your program one last time.
114-
115-
make hello
116-
117-
You should see that `make` executes `clang` with even more command-line arguments for you? More on those, too, another time!
118-
119-
Now execute the program itself one last time by executing the below.
120-
121-
./hello
122-
123-
Phew!
12+
Now let's make it a bit more interactive.
12413

12514

12615
## Specification: getting user input
12716

128-
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.
17+
No matter how you compile or execute the program, it only ever prints `hello, world`. Let's personalize it a bit, just as we did in class.
12918

13019
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.
13120

@@ -181,15 +70,3 @@ Recall that, to use `get_string`, you need to include `cs50.h` (in which `get_st
18170
To verify whether your program is indeed running according to the specification, you may use `check50` in the Terminal. Make sure that your Terminal is still pointing towards the directory that your `hello.c` resides in!
18271

18372
check50 -l minprog/cs50x/2020/hello
184-
185-
## How to submit
186-
187-
As soon as you're done, submit your `hello.c` implementation, below!
188-
189-
1. Make sure you are signed in to this website!
190-
191-
1. In the form below, browse to your `Programming` directory to find `hello.c`.
192-
193-
1. Press "Submit for grading". Presto!
194-
195-
Your program will then again be checked using `check50` and the result will be recorded on this website. Should the check fail on this website, double-check if your code still works well on your own computer by compiling and running!

0 commit comments

Comments
 (0)