Hello and welcome back.
In this lecture I want to provide a solution to your first challenge.
So this is very exciting.
Remember that we had our first challenge and our challenge was to write a C program that displays your
first name as output.
And so you're going to write and run your first C program.
You're going to need to follow all the steps that you do when compiling and editing and so forth.
So here's our solution.
I'm going to go ahead and select code light because code light is the IDE that we're going to use in
this class to compile and run our C programs.
So the first thing we need to do is we need to create a new workspace.
So I'm going to go up to file and I'm going to say new new workspace and I'm going to select C plus
plus as the workspace type.
Again, this we're doing C programs, but C plus plus is fine.
So we go ahead.
Okay.
And then we have to place our workspace in this particular directory.
We're going to keep it in documents for now.
And we're just going to name our workspace workspace and then we're going to hit.
Okay.
At this point, we now have a new workspace.
The next step is to create a project.
So to create a project again, we can either highlight the workspace right click and say new project,
or we can go up to file and say new project.
We're going to go ahead and say new project.
And you remember this from previous videos.
This is basically our settings for our project that we can set up.
You should probably get a meaningful name.
We're just going to call it test project, challenge number one, whatever you want to call it.
We're going to create this project in the folder.
We're going to use our template that we created previously under user templates, and we're going to
say for the type, we're going to say my template and then hit.
Okay.
And everything else can stay the same.
At this point, you should see your source file, which is main.c, created with a Hello world type
application.
Now, according to the instructions from the challenge, we're going to go ahead and delete this file
because we want to actually write our own code.
We don't want to just have everything created for us, and this is usually common practice that happens.
So we're going to say remove and we're going to remove Main.c and we're going to say, go ahead.
Yes.
Now we can create a new source file by selecting the source tab.
Right?
Clicking and saying add a new file.
Once we say add a new file, we can name this.
I think I told you to name it test and you want to make sure it has the C extension.
So test dot C and so we go ahead and we say, okay, at this point you'll see there's a test dot c file
under the test project and it also is empty.
So now we can start adding our code.
I then told you that you should just basically copy some source code that I provided for you, which
is what I'm going to do now.
The source code you don't need to fully understand yet.
I'll explain some of it in the next lecture.
Some of the basics.
But basically it contains a basic example of a C program.
There is something here on line five.
Line five is doing the main work.
It's actually outputting data to the screen using a printf function.
I gave you instructions that you should modify this to print your name.
So here in the dots you would actually type your name.
I'm going to type Jason.
You then have to make sure the file is saved.
So I'm going to hit control s or I'm going to go up to file and I'm going to say save all files.
Once it's saved, you then want to follow the process of compilation, linking and running in order
to compile this code.
We have to go up to the build menu option and we have to say build.
That will issue the compilation command.
When we say that, you'll see when we execute that, you'll see in the build log window, you'll see
that it compiled and it also linked.
You know that it compiled because it uses dash, C uses test dot C files input and then the dash O is
doing the linking.
It's linking all those object files.
And there were no errors.
And that's what you want to see.
If you write code, you don't want to see any errors in compilation.
If there were an error there, you'd have to go back and you have to edit the source code.
I also demonstrated that once the compilation in the linking is successful, you then want to run your
program.
So you go back up to build option and you say run.
And then this will actually run your program.
It will bring up the DOS prompt window.
And you see the output here which says, Hi, my name is Jason.
And that means the program was run correctly with the correct output.
I analyzed the window and I verified that it's correct.
And so now I'm done.
If that was incorrect, I'd have to go back and edit my source file and I'd have to fix it.
And that would be part of debugging, which we haven't talked about exactly yet, but everything worked
successfully.
So we completed our first challenge.
I'm going to include the source code so that you can just download it.
Thank you.