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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:39:56+00:00 2026-06-04T06:39:56+00:00

I have a question: I am using fread to read a file. typedef struct

  • 0

I have a question:

I am using fread to read a file.

typedef struct {
    int ID1;
    int ID2;
    char string[256];
} Reg;

Reg *A = (Reg*) malloc(sizeof(Reg)*size);

size = FILESIZE/sizeof(Reg);

fread (A, sizeof(Reg), size, FILEREAD);

Using a loop, consecutively call this call, to make me read my entire file.

What will happen when I get near the end of the file, and I can not read “size” * sizeof (Reg), or if you are only available to read half this amount, what will happen with my array A. It will be completed? The function will return an error?

Knowing how the file was read by the fread through?

Edi1: Exactly, if the division is not exact, when I read the last bit smaller file size that I’ll read things that are not on file, I’m wondering with my vector resize to the amount of bytes that I can read, or develop a dynamic better.

  • 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-06-04T06:39:58+00:00Added an answer on June 4, 2026 at 6:39 am

    fread returns the number of records it read. Anything beyond that in your buffer may be mangled, do not rely on that data.

    fread returns the number of full items actually read, which may be
    less than count if an error occurs or if the end of the file is
    encountered before reaching count.

    The function will not read past the end of the file : the most likely occurrence is that you will get a bunch of full buffers and then a (final) partial buffer read, unless the file size is an exact multiple of your buffer length.

    Your logic needs to accommodate this – the file size gives you the expected total number of records so it should not be hard to ignore trailing data in the buffer (after the final fread call) that corresponds to uninitialized records. A ‘records remaining to read’ counter would be one approach.

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

Sidebar

Related Questions

i have a question about using GalleryView. At first, i set five default images
I have a question regarding using Semaphores HANDLE WINAPI CreateSemaphore(...); Is there anyway I
I have a question about using subqueries in an Update statement. My example: UPDATE
I have a question about using multiple .htaccess files - I couldn't find the
I have a question regarding the method i am using for doing Business Rule
I Have a question about finding html tags using Java and Regex. I am
i have a (perhaps stupid) question: im using 2 threads, one is writing floats
I have a question regarding the integration of business objects developed using Linq To
I have a question about how to make marquee text smooth (using Qt 4.5.3)
I have a question considering a program that stimulates a stack (not using any

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.