 Hello and welcome. This video is part of a series. It's number four in the series on C programming and just looking over some basic stuff. I'm trying to keep these videos short. Today we're going to look at if then statements. I almost used an if then statement in the last video, then I realized I hadn't shown you them yet, so I left that out. Now we're going to look at it. We're going to look at, right now we've created a program called name. If we type that and say type in our name and it adds it, it types it once that includes a new line character from when the user presses enter and then afterwards, which we remove it. So let's go ahead and look at our code. I'm using Vim as my text editor. Use whatever text editor you prefer. And I'm going to clean this up a little bit. We don't need this, so we're just going to remove that and print it. But we want to make sure that we get some sort of input from the user. So after our F gets command, we're going to do an if then statement. We're going to say if and then parentheses here. We're going to give it something to look at. Again, we have this string header here, which allows us to look at the length of strings. So what I'm going to do here is I'm going to say str, which is for string le n. So that's string length. That's a command, a function. And in there, we're going to give it our name variable, which we are collecting right here. Okay, so we're going to look at that and we're going to say if that is less than or equal to one, what are we going to do? So why am I saying less than or equal to one? Because at this point, we have that new line character, which we don't want. So depending on where you want that, we could actually, if we were to take these two lines and move them up to here, we should be able to say equals zero. All depends on what you're looking at because there's always going to be at least one character from f gets because the user hits enter. But if we're removing it before checking this, let's give that a try. That's not how I originally did it. And I'm being brave right now. So if I mess up, we'll go back and fix it. We're saying, okay, if it is equal to zero, we got to do something. And I'm going to move this down here. I will do this. So we're going to say if it's zero, so if the user didn't enter anything, we are going to say a name is needed, new line. And then after that, it will exit the program. It'll return zero. But actually, it failed. So we probably want to appear return one. That means the program failed. If a user name is required, it failed. It's up to you whether you consider that a fail or not. And if it did succeed, and then it's going to say hello, whatever the name is, and print out that message. Let's go ahead and give that a try. We're gonna say GCC, the name of our input file, output name, no errors. That's good. No warnings. We're gonna say name. And if I type in Chris, it'll say, Hello, Chris, how are you? And again, there should be a question mark in there. Let's fix that. Recompile that. Run it again. Chris, how are you? And again, there's a limit of 20 characters because that's what we set name to be the max of. So if I was to run through this like so, you can see that it didn't get all the way through. And how are you? So remember, you're setting a max of 20 characters. So whatever input you're getting, think about what the max would be for that. Again, you could use f get or just gets, but that's dangerous as we talked about. But if I leave it empty and I hit enter here, it should say a name is needed. So a name is needed. And it exits out. We can also print another message in there. So I can say a name is needed. And on the same line because I have a new line character, I can say, Goodbye, recompile it, run it again. If I leave a blank, it says name is needed. Goodbye. And I probably should put a new line character at the end of that as well. So I can do that as two print F commands or one print F command. All depends on how I want. You can see we did that return one and the return zero. So if it gets all the way to the end of the function, it's successful. It gets this point. It failed, right? So how do we check that that's something you can do? So if I was to say echo, I believe it's dollar sign or I'm sorry, question mark. No, no, no. Echo. It's actually dollar sign question mark. This is a variable. So you see it says one. That's because the last command failed. This one failed. But if it was successful, like this last one was, it will be a zero. So here's an example of that. I can say again, name. If I type in Chris, hit enter. And then I say echo dollar sign zero. Sorry, dollar sign question mark. I should get a zero because it was successful. If I run the command again and leave it blank and then check the exit code, it's giving me a one. And that's a great way to check if someone's going to use your program. If they want to know if it was successful or not, they can check that. And there's different ways to check that. In most shells, you can echo out dollar sign question mark and will give you the exit code of the last command. So that's a little bonus since we're just looking at if then statements. But now you know what that return is all about. So that's this code. Again, you can go to gitlab.com forward slash metal x 1000 forward slash my bin capital M capital B. There's projects here with a bunch of different just basic little example codes that I've created. And if you go under the C folder, there's tutorials. And these are all example codes based on the tutorials we're going through right now in these videos. You can also visit films by Chris.com. That's Chris of the K. There's a link in the description. And there you can search through all my videos and scripts and tutorials. And that's great. I do thank you for watching. And as always, I hope that you have a great day.