stdio.h
that we include, are actually included.cs50.c
or printf.c
, are linked, or merged with our program.help50
, which might help us understand error messagesprintf
, which can help us understand our program as it runsstyle50
, which checks the style of our code so it’s more readable and consistentCS50 IDE is like the CS50 Sandbox, but with more features. It is an online development environment, with a code editor and a terminal window, but also tools for debugging and collaborating:
Once we log in, we’ll see a workspace that looks similar to that of CS50 Sandbox, but now our workspace will be saved to our account.
We can create a new file with File > New File (or the green plus sign), and use File > Save to save it as hello.c
in the folder ~/workspace/
. Now we’ll write our simple program:
#include <stdio.h>
int main(void)
{
printf("hello, world\\n");
}
Now, in the terminal window below, we can type make hello
and ./hello
to see our program run.
The folder icon at the top left will show us all our files in a directory (folder) called ~/workspace/
, and we can create folders and files inside. The ~
symbol refers to our home directory in this environment, which is just the set of all the files related to our account, and workspace
is a folder inside ~
that we can use. (The ~
directory also has other configuration files for our account, but we won’t need to worry about them.)
In the terminal, we see ~/workspace/ $
. The $
part of the prompt is the same as before, after which we can type a command, but the first part of the prompt tells us the directory our terminal is in. For example, we can type ls
, and we’ll see a textual version of the workspace
directory. And ./hello
refers to a file called hello
in .
, which is the current folder.
We can change our directory with cd
, and if we type something like cd src3
(assuming we have a folder already named src3
), we’ll see our prompt change to ~/workspace/src3/ $
.
We can delete files and folders with the graphical file tree, right-clicking them as we might be familiar with already. But we can do the same in the command line, with rm hello
, which will remove files. The command will ask us for a confirmation, and we can type yes
or y
(or n
, if we’ve changed our minds).
We can create directories with mkdir test
, and rmdir
to remove them.
In the CS50 IDE, we’ve also added another tool, check50
. Like style50
, we wrote this tool to automatically check the correctness of your programs, by passing in inputs and looking at their outputs.
After we write a program from a problem set, and have tested it ourselves with a few inputs, we can type check50 cs50/2018/fall/hello
. The cs50/2018/fall/hello
is an indicator for the program specification that check50
should check, and once we run that command, we’ll see check50
uploading our code and checking it.
We can also now use a tool called a debugger, built into the CS50 IDE.
After we compile our code, we can run debug50 ./hello
, which will tell us to set a breakpoint first. A breakpoint indicates a line of code where the debugger should pause our program, until we choose to continue it. For example, we can click to the left of a line of our code, and a red circle will appear: