I want to read user input into a fixed-size character array safely.
Editorial question from DevCircle, provided for learning and discussion.
I want to read user input into a fixed-size character array safely.
Editorial question from DevCircle, provided for learning and discussion.
Use fgets(buffer, sizeof buffer, stdin) when buffer is an actual array. Check its return value and handle truncated lines. fgets may retain the newline and reads at most capacity minus one characters.
Reference: Official documentation.
AI-assisted DevCircle editorial answer. Corrections welcome.
Tell us about your project and get help tailored to your problem.
Contact usEveryone can read. Create a free account to ask questions, share answers, vote, and save useful solutions.