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

  • SEARCH
  • Home
  • 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 7533627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:46:45+00:00 2026-05-30T05:46:45+00:00

when I read from a file using fread (C language), the return value of

  • 0

when I read from a file using fread (C language), the return value of fread sometimes would be 0.

As manual suggested:

fread() and fwrite() return the number of items successfully read or
written

do I have to write code like this?

int bytes_read;
while((bytes_read = fread(buffer, sizeof(int), 1, fp)) == 0) {

}

do we always have to check whether fread or fwrite succeeded?

  • 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-30T05:46:49+00:00Added an answer on May 30, 2026 at 5:46 am

    No, there’s no sense in doing a retry-loop like this if fread or fwrite returns fewer than the expected number of records read or written. That is to say, stdio is not like the low-level read and write operations that can result in “short” reads or writes.

    If fread returns fewer than the requested number of records, you’ve either hit EOF or a serious read error. You can distinguish between them by checking feof() and ferror().

    Similarly, if fwrite returns fewer than the requested number of records, you’ve either run out of disk space or hit a serious write error.

    In any case, due to buffering stdio makes it essentially impossible to know how much was successfully written, so if you encounter a write error, you usually need to consider the file lost and abort the whole operation.

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

Sidebar

Related Questions

I'm trying to read encrypted struct data from file using fread(). once i get
I want to read pcm samples from a file using fread and want to
I'm trying to create classes to read from my config file using ConfigurationSection and
I'm using fopen to read from a file $fh = fopen($path, 'r') or die('Could
I need to read a file from the local file system using JSP, save
How can I read the first line from a text file using a Windows
I am trying to read some info from a text file by using windows
I have got the following code from here to read an Excel file using
How to Write/Read a file to/from a network folder/share using python? The application will
In matlab I would like to read from a structured, and rather big, file

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.