0:00 Hey, what's going on everybody? In this video, I'm going to teach you everything you need to know to start coding in C. This video contains 12 hands-on projects, and for our final project, we will code a working clock. If that sounds good to you, I encourage you to sit back, relax, and enjoy the show. I don't like boring introductions, so we're just going to jump right in. To start coding in C, you'll need two things. An IDE, that's an integrated development environment. It's a workspace in which we can write code. The other thing we'll need is a C compiler. It converts our written code into machine code so a computer can understand it. In this next section, we're going to install an IDE. In this next section, we're going to download Visual Studio Code. It's a place in which we can write code. You can head to this URL code.visisualstudio.com. Once you're here, go to this blue download button in the corner and then select the correct download for your operating system. I'm 1:00 running Windows, so I will download the Windows version. And our download should start automatically. Now that our download is complete, we're going to open this executable. Read the license agreement. Yes, I did read it that fast. I accept the agreement. Next, you can select a destination folder. I'll keep it the same. Next. Next. You can create a desktop icon if you would like. I think I'll do so. Next. And install. And then just give it a moment. We might as well launch Visual Studio Code right away. I'll keep that checked. And finish. Here we are within Visual Studio Code. We're going to create a new project folder. We can close out of this menu. Go to the left 2:01 toolbar. Go to the explore tab. And we will open a folder and or create a new one. Pick a place in which you would like to create a new folder. I'll do so on my desktop. I'm going to rightclick, go to new folder. I'll call this folder coding, but feel free to pick something else if you would like. Click on your folder, then click this button of select folder. Now, we're going to create a new C file. Within your folder, we're going to go to new file. A common naming convention for a C file is main because it holds the main body of your code. main C. Enter. We're within an empty C file. There's a few extensions I would recommend. Let's go to the left toolbar. Go to extensions. And we are going to look up the C/ C++ 3:02 extension. C/ C++ extension pack. This will give us some quality of life improvements for C programming. So, be sure to download this extension. Once this extension is downloaded, the next extension is the CodeRunner extension. So, look up CodeRunner and install. Okay, we can close out of this extensions menu and go back to the Explorer window. For the CodeRunner extension, there's two settings I recommend enabling before we continue. Let's go to file, preferences, settings. We're going to look up code runner. Check this check box of clear previous output. That'll clear the output before we run each program. And then scroll down, check save file before run. So you 4:04 don't have to manually save each time we want to run a program. And those are the two settings I would recommend for the CodeRunner extension. Next on our to-do list is to check to see if we have a C compiler already installed. To do that in VS Code, you can go to the terminal tab. Go to new terminal. Now, the instructions are going to vary based on your operating system. Currently, I'm running Windows. To check to see if you have a C compiler using Windows, you'll type GCC- version. If you don't have one installed and setup, you'll see an error message like this. The term GCC is not recognized. But if you're on Windows and you do have one installed, you'll see something like this. GCC- version. And here's my compiler, gcc.exe. And then I have a version number and some other copyright stuff. Let's clear this terminal. If you 5:04 need to set up the C compiler for Windows, it's actually really complicated. Look in the description of this video for any timestamps and you can skip ahead. If you're a Mac user, you're going to type C lang dash version. This is how to check to see if you have a C compiler using a Mac. But since I'm on Windows, this term isn't recognized. To install the C compiler on Mac, it's actually pretty simple. type xc code dash select dash install. This will install the C compiler and some dev tools. But again, I'm on Windows. These terms aren't recognized. If you're a Linux user, to check to see if you have a C compiler, you'll type GCC-V. If you're on Linux and you don't have a C compiler set up, you'll type pseudoapp-get update. This will refresh the package list. Hit enter. Then to 6:06 install the C compiler, you'll type if you're on Linux pseudoapp-get install build essential gdb. This will install the compiler, make, and debugger. Again, this is if you're a Linux user. So, if you're on Windows, we need to set up the Windows installation. Our next step is that we have to download a compiler. It will translate our written code into machine code. To make this as easy as possible, I recommend going to this website, mcs2.org. MSYS 2 is a collection of tools and libraries for building, installing, and running native Windows software. We can really just follow the installation instructions. The compiler is going to be provided with this. We'll download the installer. Then we just have to wait for it. Also, please note to run the installer, this requires 64bit Windows 7:08 10 or newer. Once the download is complete, we'll open this executable. Click next. Select a destination folder. I'll keep it as is within my C drive. Next. You can create a start menu shortcut. I'll just press next. And we are installing. We'll run MSYS 2 now. Keep this box checked and finish. We'll use this piece of software MS 2 to download the C compiler. Here's how. Now according to our instructions, the next step is that we have to type this command. Honestly, we can just copy this. Copy and paste. Pac-Man means package manager, not the arcade game. Dash capital S for sync. And here's the name of the package. It's really 8:08 long. Then I'll hit enter to submit it. proceed with the installation. Capital Y for yes. And this will take a moment. We're downloading all the packages we'll need. Let's ensure that our compiler downloaded successfully. You can type gcc- version. It should display the current version of the C compiler that we're using. All right, we can close out of this window. And now we need to set the variable path. Let's locate that folder. It's within my C drive, MS64. We need to find the C compiler. It should be underneath this folder of UCRT64. Go to bin and we are looking for this file. We're going to copy the file location. I'll right click, go to properties, and copy this location. 9:11 What we got to do next is set the path variable. We have to let our operating system know where it can find the C compiler that GCC file. We're going to do a search for environment variables. Edit the system environment variables. Click environment variables. Select path. Edit. New. Then paste that path and it should be to that GCC file. Press okay. Then okay. Okay. And that's it. We have downloaded and set up the C compiler from Windows. All right. We're ready to write our first C program within our C file. The first thing we're going to write is this statement. pound sign include then within angle brackets std io.h. This statement is a pre-processor 10:12 directive. We're telling the compiler to include the standard input output library. It contains a lot of useful functions for output and input. We need this header file in order to display text to the screen. Later on in this program, we need a main function in order for this program to well function. Here's how to create the main function. You'll type int, meaning integer. The entry point for a program is the main function. Main. Add a set of parenthesis, then a set of curly braces. Your program is not going to run without the main function. We can even try it. I'm going to cut it temporarily. To run your C program, go to this arrow and select run code. There's also a shortcut if you would like to use that, too. Well, without the main function, we get this error message. Returned one exit status. I'll paste the main function back in. Now, we don't get that error message. And we do have an executable within our coding folder. Our program is 11:12 running successfully, but it doesn't do anything. So, you need the main function in order for your program to well function. It's the entry point of your program. What you'll commonly see at the end of the main function is this statement. Return zero semicolon. In the C programming language, the main function is expected to return an integer. It returns it to the operating system. This integer serves as an exit code. Zero indicates that the program ran successfully. A nonzero value typically indicates an error, an error or problem of some kind. In older versions of C such as C89 or C90, omitting this statement will lead to undefined behavior. But in later standards, you can omit the statement. But it's considered good practice to include this return statement just for backwards compatibility. We have a program, but it doesn't do anything. So let's print some text. The main function is the entry 12:13 point of our program. Within the set of curly braces, we'll write some code that we want to print. To print some code, you can use the print f statement. print f ( (en)), then a semicolon at the end. We end all of our statements with a semicolon. It's kind of like the period at the end of a sentence in the English language. Whatever you would like to print to the screen, you're going to do so within quotes, double quotes. Think of a food you like. My first statement will be I like pizza exclamation point. And now if we were to run this program, we can print this text. So let's run this code. And the output is I like pizza. Let's add a second print f statement. Print f. Let's say it's really good. Then be sure to include that semicolon at the end. Now we should have two lines of output. I like pizza. It's really good. 13:14 One issue that we're running into is that we're displaying all of the text in one line. To move down to the next line, you can add a new line character, which is a forward slash and an N. That's a new line character. Now, our next line of output should be on the next line. I like pizza. It's really good. To print some text to the screen, you just type print f, then within quotes, add some text. Now we're going to discuss comments. To write a comment in C, you use two forward slashes. Then you can write some text. For example, let's say this is my first program. Comments won't display as output. And you can see that the text color is green. But that's a feature of VS Code. If I were to run this program, we don't see this comment. We still have our output. I like pizza. It's really good. Comments are useful as notes for yourself or for other 14:16 developers. You can also write a multi-line comment. To start a multi-line comment, use a forward slash, then an asterisk. You'll have an asterisk, then a forward slash again, wherever the comment ends. We could say something like this is also a comment. This won't display as output either. We still have I like pizza. It's really good. Throughout the series, I'll be writing a lot of comments. And that's your first lesson in C. Now, you have a homework assignment. In the comment section down below, you have to write two comments and two print statements. If you don't do your homework, I'm going to call the police and they're going to come to your house and arrest you. And well, everybody, that is your first lesson in C programming.