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 6709459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:53:04+00:00 2026-05-26T07:53:04+00:00

I have two questions about C’s fread function: I have read that fread is

  • 0

I have two questions about C’s fread function:

  1. I have read that fread is used to read a binary file. However, when I read a binary file with fgets using read mode "r" and a text file with fread using "rb" mode, the results are the same as reading a text file with fgets and a binary file with fread. So, why are there different functions for reading binary and text files?

  2. I am using fread to read 10 bytes of a file in one call. How should I stop reading at the end of file – i.e. how is EOF specified in fread?

  • 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-26T07:53:05+00:00Added an answer on May 26, 2026 at 7:53 am

    answer of 1 question >

    1>fread

    size_t fread ( void * ptr, size_t size, size_t count, FILE * stream );
    

    Read block of data from stream (try to understand this)

    Reads an array of count elements, each one with a size of size bytes, from the stream and stores them in the block of memory specified by ptr.
    The postion indicator of the stream is advanced by the total amount of bytes read.
    The total amount of bytes read if successful is (size * count).

    2>fgets

    char * fgets ( char * str, int num, FILE * stream );
    

    Get string from stream (try to understand this)

    Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or a the End-of-File is reached, whichever comes first.
    A newline character makes fgets stop reading, but it is considered a valid character and therefore it is included in the string copied to str.
    A null character is automatically appended in str after the characters read to signal the end of the C string.


    answer of 2nd question
    in fread return value is

    The total number of elements successfully read is returned as a size_t object, which is an integral data type.
    If this number differs from the count parameter, either an error occured or the End Of File was reached.

    You can use either ferror or feof to check whether an error happened or the End-of-File was reached.

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

Sidebar

Related Questions

I have two questions about using a BackgroundWorker: 1)Lets say you have Function A
I have two questions about Google's dense_hash_map , which can be used instead of
I'll cut to the chase. I have two questions about switch that are simple,
I have two questions regarding binary search trees, both about empty trees. Is an
I have two questions about binary search trees - one about the code I
These are two questions about static locals that have always bothered me and I
i'm searching about image filters using ios5 sdk but i have two questions: For
I have two questions about java.awt.Shape . Suppose I have two Shape s, shape1
So I have two questions about HashMap s in Java: What is the correct
I have two noobish questions about Flash, Actionscript, Flex etc. 1) With these technologies

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.