C in 100 Seconds: Safe Input with fgets | Episode 13

0views
00
2:16
T
Taught by Celeste AI - AI Coding Coach
View on YouTube
Description
scanf reads one word and has no length limit — fgets is the safer alternative. It reads a full line with a size cap, so your buffer never overflows. Three arguments: the buffer, the max size, and stdin. It reads up to size minus one characters and adds the null terminator. One catch — fgets keeps the trailing newline. Use strcspn to find it and replace it with zero. Student code: https://github.com/GoCelesteAI/c-in-100-seconds/tree/main/episode13 What You'll Learn: • fgets reads a full line, not just one word • Buffer size limits how much it reads — no overflow • stdin means read from the keyboard • strcspn strips the trailing newline • Safer than scanf %s for string input Next: Episode 14 — Constants and Macros #c #programming #100seconds #learnc #fgets #stdin #bufferoverflow #safeinput #strcspn #tutorial Tags c fgets, safe input c, buffer overflow c, stdin c, strcspn c, fgets vs scanf, c tutorial 2026, c beginner, 100 seconds, learn c, coding tutorial

Tags

c fgetssafe input cbuffer overflow cstdin cstrcspn cfgets vs scanfc tutorial 2026c beginner100 secondslearn ccoding tutorial
Back to tutorials

Duration

2:16

Published

April 7, 2026

Added to Codegiz

April 8, 2026

Open in YouTube