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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:10:51+00:00 2026-05-23T13:10:51+00:00

first time posting here, Googled for a few hours and I couldn’t find anything.

  • 0

first time posting here, Googled for a few hours and I couldn’t find anything.

I am trying to write a client program that reads different files and sends them over the web to a server program. (For backup purposes.)

So far I have used fread() to put the files into a buffer, in a way that is similar to this:
http://www.cplusplus.com/reference/clibrary/cstdio/fread/

It works fine for plain-text files, but when I try to transfer executable files, fread() doesn’t seem to read the files, only reading “ELF” into the buffer.

My question is, what is the proper way to read the contents of an ELF file into a buffer in C?

Thank you.

  • 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-23T13:10:52+00:00Added an answer on May 23, 2026 at 1:10 pm

    The proper way to read binary files is simply to use fread(). But remember that you cannot treat the contents as a string, which means (among other things) you cannot use strlen() to determine their length.

    Instead, you must keep the length in a seperate variable. The return value of fread() will tell you how many records it successfully read – if you set the record size to 1 (the second parameter to fread()) then it will return the number of bytes read.

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

Sidebar

Related Questions

first time posting here. I'm using a loop to create 3 buttons, but my
this is my first time posting here, I have a question which I have
this is my first time posting on here and have read alot of helpful
this is my first time posting a question here - I've searched for ones
first time posting here after having so many of my Google results come up
First time posting on stack overflow. I've spent hours scouring over many Google searches
this is my first time posting my problem here, i hope i get help
First time posting here after having great results searching for other answers on stackoverflow.
First time posting on here, so I hope I do this correctly, however I
First time posting here. I have problem about referencing a typedef struct from separate

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.