 Hello, and welcome. This is video number two in a series on C programming, trying to keep these short, very basic videos. So we're going to jump right into it. I'm going to use Vim as my text editor. You can use whatever text editor you want. I'm going to call this name.C. And what we're going to do today is get user input. And there's different ways of doing that for different scenarios. We're going to be looking at getting a string. So a word, a group of characters from a user. And there's a few different ways to do that. I'm going to go in here. And of course, I'm going to start off with pound.Pound include less than greater than in here. I'm going to say stdio.h. So our standard input output, you're going to have that pretty much in all your C programs. We're going to say main. So our main function, which if successful return a zero, don't forget our semi column there. And again, we're going to get the user name. So we want to ask for something. I'll say printf. And here I'm going to say, enter your name colon. And I'm not going to do a new line character there because I want them typing it on that same line, just depending on the look you want. Again, we talked about new line characters in the last video. And here we're going to use gets. So gets is a simple way to get user input, but also can be kind of dangerous. But I want to show it to you and then we'll talk about it a little bit more. But let's create our variable here. We're going to create char name. And we'll say it will be 20 characters. So that is our variable. Then down here, I'm going to say gets. So in the gets function, I'm going to say name. And then we should be able to printf and say hello name or sorry, hello, percent s, because this is a string comma. And then the string we're going to put in there is the name that we got. We're going to go ahead and do that. We're going to compile it again with GCC, the name of our input file dash o for output. We'll just call it name again. If you're on a Windows system, you won't be named.exe. And at the end of the series, we will look into cross-compiling for Windows. If I did everything right, I did something wrong. Oh, no, it's just warning me not to use gets because it could be dangerous. And we're going to talk about that. But it did compile it. So I can say dot slash name. It's going to enter my name. I'll say chris. I'll hit enter. It says hello chris. It did not put a new line character in there. So I can go back into here and I can add that in right after s here. So we get that new line. All depending on what you want. So I'll compile that again. Again, it's it's not an error. It's a warning not to use gets. And we'll say name. And now I'll say my name is chris. It says hello chris and put the new line character in there. Although if you don't want the new line character, you can go ahead and and I'm bringing this up because we're going to show another way that includes your new line character. I can just say here, well, I can add that new line character. Hello chris. How are you like that? Compile it again. Run it again. Again, we get that same error because you really shouldn't use gets. But I'll say this and I'll just say john. And it says hello john. How are you should have been a question mark there doesn't matter. Let's go ahead and go back into our code here and get rid of this gets. So what gets does I put 20 characters or actually let me show you something real quick. We'll undo that and we'll say two characters here. I will compile this and then I'll say name and I'll again say chris. Now we said that the name should only be two characters. But look, it recognized it as all four characters. And that's bad. With a guy getting too much into it. If you ever heard of buffer overflow, this calls buffer overflow, you're putting in you're saying the name should be this long, but it's allowing pretty much any length. There's no check to it. So that's where f gets comes in. So instead of gets, we're going to say f gets. Now f gets will only allow the number of characters that we are including there. So if I come in here and I compile this, what did I do wrong here? What's it warning me here? File include not declared. Oh yes. So yeah, it's not just giving it the variable you want. We want to give it the variable you want. And then we want to give it the length that f gets is going to allow it to capture, which should be the length of our variable. So I could say two, but you don't want to do that because you might change the length of that up here. So what we're going to do is we're going to use size of name. So that way, however size we say name is it will put that in. And then we're gonna say standard input is what we're capturing. Now let's compile that. No errors. That's good. Let's do dot slash name. And I'll say Chris. Now you can see it only got the K. Now we said two characters. Why is it cutting it short there? The the answer is that we have to give it a larger length there. But we also have to realize that f gets is going to capture your new line character. So when we use gets, it didn't capture that enter. F gets will. And if you don't want that, you got to remove it, which we'll talk about in the next video. Let's go back into our code here. Name not C. So unlike gets, you have to know the maximum length. So I'm gonna say 20 characters here. And again, since we did name a size of name here, we don't have to retype anything here. It's going to look at the size of that. So now I can run the I got to recompile it. And then I'll run it again. And now I can say Chris and we'll put Chris. You see it captured that new line character so that how are you is on the next line. So we would have to remove that if we didn't want that again, we're gonna look at that in the next video. But if I was to run this and I was to type out a bunch of stuff, you can see it stops at the 20th character. It's not gonna let you go any further than that, which is good. I mean, you have to know what range of letters that you're gonna put in, but it's not going to allow to go past where it should. So that's why f gets is safer. So that's basic look at that. Again, if you go to get lab.com forward slash mail x 1000 forward slash capital my bins, that's capital M and capital B. In this project. So let me go up to the main part of it. There is a C folder and a folder called tutorials and all the code we're going through here or at least similar ones are going to be in here. So you can get all the source code from these tutorials. Here's the one we're working on. So it's a little different. I think I have two lines here, but same concept. So you can follow through there and then you can compile them using that compile all script. It will compile into this bin folder or you can manually compile them. So check that out. Also check out films by Chris dot com. That's Chris the K. There's a link in the description to that and hopefully this and there you can search through all my videos and tutorials and scripts. And as always, I hope that you have a great day.