Read Single Character (fgetc())

1 minutes
Share the link to this page
Copied
  Completed
The fgetc() function is used to read a single character from a file.

Transcript

Hello, in this video we are going to look at reading a single character. So at the moment, we've got it so it checks if you're at the end of the file or not, I just read every single line from the file pretty simple. For now, I'm going to comment at this. And to read a single case, all you do is F, get C. So basically yourself or get character in a fall the character specify the file, and we put a closure side. So if I run it, we should just get h now, there we go. So we could duplicate this several times.

Got to say that and never run it, we get how because if we do one more, we'll get the O from Hello. What we can do instead is we can start at the new because the end of fall works wherever you're getting an entire line or you'll get in the in just one character so I'm going to get there Put this here. Go to that. So now when you do, you'll go for every single character and you will put a, you're putting on a new line, which includes the new line characters. So there you go. So that is how you read a single character.

What I want you to do is combine both of them have this while loop which checks have you reached the end of the fall inside there, I want you to basically get every single line and then from that line that you get, recommend the store into a variable have a normal loop, which basically goes over that line and get every single character that can be extremely useful when you're dealing with files. That's it. If you have any questions, feel free to pop me a message. And as usual, I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.