- Programming involves writing source code,
compiling and linking, which creates the program.
You then test run the program to see
how it works, or if it works.
In this movie, I'll demonstrate
that process in Code::Blocks.
You'll see how to set up and run a sample project.
I'll also show you how to understand and fix problems
by using the Code::Blocks IDE.
Start up Code::Blocks, if you haven't already.
You need to see the Start Page, and if you don't
see it, choose View, Start Page.
Most of the work you do in Code::Blocks is project-oriented.
Projects can be anything from a small program
to a massive online game.
For this course, you'll be
using the pre-written exercise files.
But, normally in Code::Blocks, you create a project,
typically by clicking the Create a new project link.
This step isn't needed in this course,
because, like I said, I've pre-written
all the exercise files for you.
But, if you wanted to create a new project in Code::Blocks,
specifically one of the console applications demonstrated
in this course, choose Console application
when starting a new project.
Select the C language.
Type in a name for the project and choose a folder,
such as the exercise folder created in an earlier movie.
On the Mac, ensure that the names don't have any spaces
or the program can't be run from within Code::Blocks.
Choose "Release" only, and click Finish.
Open the main C source file to begin editing.
Although this is a complete program,
it's presented as a skeleton.
Otherwise, that's all you need to know
about the Code::Blocks Start Page.
Dismiss this project by right-clicking on it
and choosing Close project.
In this course, you'll be incorporating pre-written
source code files for use in the IDE.
This saves you typing time, but it also saves you
editing time from creating a new project and then
editing that Code::Blocks pre-written source code skeleton.
To open one of this course's exercise files in Code::Blocks,
click the Open button on the toolbar.
Browse to the folder containing the exercise files,
such as the C Programming folder.
Choose the exercise file 01-04_welcome.
Open that file.
There, you see the source code.
C code does not include line numbers, but the editor
shows line numbers in this column.
These are handy for reference in this course,
but also for tracking down errors, and the
source code itself appears here.
The text is color-coded, which helps you recognize
different parts of C, as well as spot errors
when things aren't colored correctly.
The next step after writing the source code
is to compile a link.
In Code::Blocks, that step is combined
into a single action called Build.
To build your project, click the Build icon, here.
The action takes place at the bottom of the screen
in the Build log, and then Build messages tab.
Yes, these errors are on purpose.
I want you to see how the errors appear.
Click the Build log tab to review the specific messages.
You see what's wrong, which may not make sense
to you right now, but it will in the future.
More importantly, you see a line number, line five.
In this case, line five is missing a double quote.
In the editor, click here to add a double quote character.
If you've done it correctly, then only the text
in double quotes is colored blue, not the parentheses
or semicolon at the end of the line.
Save the file.
Click the Build button again, and there's still an error.
Click the message to locate the error in the code,
or click the Build log to see more specifics.
Some compilers, such as Clang, are more specific
about warnings and errors.
At the end of line six, type a semicolon.
Save the file.
Build.
No warnings, no errors, that's good.
It's what you wanna see.
Now, on the Macintosh, you may
see a warning about option -s.
That's a linker error and you can ignore it.
Click the Run button to witness the program's brilliance.
In Windows, the program runs in a command prompt window.
On the Mac and Linux, a terminal window appears.
In that window, you may also see
any start-up scripts you've written.
Ignore that part of the output, otherwise what you
see is the program's output, shown here as,
"Welcome to the C Language!"
Close the output window and return to Code::Blocks.
In Windows, press the Enter key.
If the terminal window doesn't close in Unix,
type the Exit command and then press the Enter key.
I recommend you do this, otherwise those
terminal windows will stack up.
You're now ready to move on to the next project.
If you shut down Code::Blocks, you may be asked
whether or not you want to save the perspective.
Click Yes.