High Definition Standard Definition Theater
Video id : zWIgtikk6ig
ImmersiveAmbientModecolor: #eeeae9 (color 1)
Video Format : 22 (720p) openh264 ( https://github.com/cisco/openh264) mp4a.40.2 | 44100Hz
Audio Format: Opus - Normalized audio
PokeTubeEncryptID: c6747d555d4e3ab42d0ecbe356de927333708c6ddb92a85032b6f39cef00ec2afb5d54dec1baf73c0e7013ec4ff62849
Proxy : eu-proxy.poketube.fun - refresh the page to change the proxy location
Date : 1715720806900 - unknown on Apple WebKit
Mystery text : eldJZ3Rpa2s2aWcgaSAgbG92ICB1IGV1LXByb3h5LnBva2V0dWJlLmZ1bg==
143 : true
fgets is unsafe! So what’s the alternative?
Jump to Connections
2,376 Views • Nov 7, 2022 • Click to toggle off description
fgets is often described as a “safe” C function – one you should use instead of gets or scanf.

But is it really safe?

The plain answer is: NO. You can very easily corrupt data by reading unintended characters from the command prompt using fgets, as I explain in this video.

In previous videos I’ve already shown that standard C line-reading functions are unsafe so if fgets is unsafe too, what should you use instead?

In this lesson, I explain the problems and suggest some solutions.

To follow the course in order, bookmark the playlist:
   • Program C in Visual Studio  

PROGRAMMING BOOKS
====================
If you want to learn C in more depth (and also support this channel!) you might think of buying one of my books. I have written books on C programming, Using Pointers in C, Recursion and other programming topics.

** The Little Book Of C Programming **
Amazon (US) amzn.to/2RXwA6a
Amazon (UK) amzn.to/2JhlwOA

GET THE SOURCE CODE
=================================
Download the source code of the projects in this course (the archive for “The Little Book Of C”) from:
www.bitwisebooks.com/

“CODE WITH HUW” ON TWITTER:
=================================
twitter.com/codewithhuw

“CODE WITH HUW” ON FACEBOOK:
=================================
www.facebook.com/CodeWithHuw

Good luck! And good programming!
Metadata And Engagement

Views : 2,376
Genre: Education
Date of upload: Nov 7, 2022 ^^


Rating : 5 (0/93 LTDR)
RYD date created : 2024-04-21T04:22:47.695335Z
See in json
Tags
Connections

YouTube Comments - 15 Comments

Top Comments of this video!! :3

@johnc3403

6 months ago

The Little Book of C Programming is on my Christmas list. A perfect companion to last years Christmas present, K&R 2ed.

1 |

@ironfist7789

8 months ago

Problem is, while windows is \n for new line, mac was \r for carriage return and some used \r\n for a newline to satisfy both (from what I recall doing this in the past). In programming muds in the 90s, a lot of codebases used \r\n in their strings.

1 |

@BitwiseMobile

1 year ago

I think the C++ standard library now includes buffer overflow safe alternatives to all our buffer overflow friends. I wrote C++ for 10 years, and then while I was working for a Microsoft subsidiary we beta tested C#. I'll never go back to the hell that is virtual destructors, new, delete, and everything associated with a non-garbage collected language. C/C++ is great when you need to get down to the metal (and I would argue on other platforms, but dotnet has been ported to pretty much everywhere now, so that argument no longer holds), but it comes with it a plethora of issues. With great power comes great responsibility (for freeing your memory, and ensuring your buffers are of the proper size).

1 |

@abdelhaylawhy631

1 year ago

I have a question: for reading numbers like int, floats, long, ... is scanf() safe? or should we think about another ways? and thanks 👍

|

@abdelhaylawhy631

1 year ago

First, I wanna thank you for this HERO function, and thanks for this amazing course. but why don't you add it in c language as Standard library functions, that will be more helpful.

|

@BryanChance

10 months ago

Yep, why don’t people just write a custom input function? Read one character at a time and limit it. c’s input routines are probably what gave C a bad name. LOL

|

@Sufian95

3 months ago

Will a fflush(stdin) workout?

1 |

Go To Top