Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6581105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:06:38+00:00 2026-05-25T16:06:38+00:00

Most C file writing examples for fputc use a very basic example with little

  • 0

Most C file writing examples for fputc use a very basic example with little or no error checking of the process.

What error-checking techniques and functions should I use in conjunction with a fputc loop to ensure that fputc has successfully written to file? And how should I use them?

The reason I ask for fputc specifically is I am working with a doubly-linked list.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:06:39+00:00Added an answer on May 25, 2026 at 4:06 pm

    Checking the return value of fputc will usually not tell you anything useful, and will make your code hideous. The reason the return value of rarely meaningful is because stdio files are buffered, and a write error (usually due to exhausting disk space, but it could also be due to hardware failure which there’s really no way to handle gracefully) will not be reported until the buffer is flushed. Because of this, it’s also impossible to know, even when an error is reported, how much was successfully committed to disk.

    As such, my view is that you should only use stdio to write files when you’re willing to consider the entire “save” operation a failure if any error occurs during writing. If you take this approach, you can completely ignore the return value of all write functions. This is because the stdio FILE keeps an internal error indicator accessible as ferror(f). So just do all your writes without checking for any errors, then before you close the file, check ferror(f). If it returns a nonzero value, you know your “save” operation failed, and you can report this to the user and remove the partially-written file. Keep in mind you should be writing first to a temporary file then rename this into place, rather than writing directly over top of your old file, unless you want to risk destroying the user’s old data on failure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a little guidance in writing a grammar to parse the log file
I've got a menu that contains, among other things, some most-recently-used file paths. The
Most of time, the source of file uploading errors are that we forget to
What is the most elegant way to solve this: open a file for reading,
In Visual Studio as most of you will have noticed that related file can
What would be the most efficient method of reading a text file into a
What is the most correct regular expression (regex) for a UNIX file path? For
I'd like a file of the 200-1000 or so most frequently used words in
What is the most portable way to play a wave file in Linux? I'd
As most of you would know, if I drop a file named app_offline.htm in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.