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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:31:19+00:00 2026-06-17T07:31:19+00:00

I am trying to read in data from a file and am confused. The

  • 0

I am trying to read in data from a file and am confused. The file contains three columns of data. With fscanf it is giving the correct values.

FILE* fp = fopen("test.txt");
double buffer[3];
fscanf(fp,"%lf %lf %lf",&buffer[0],&buffer[1],&buffer[2]);

Now I am trying to read the same set of values using _read. This gives me all the wrong values.

int fh;
char buffer[50];
_sopen_s( &fh,CStringA(PointFile),_O_RDONLY|_O_BINARY,_SH_DENYNO,0);
_read(fh,buffer,sizeof(double)*3);

It will be really helpful if someone can tell me what I am doing wrong.

  • 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-17T07:31:20+00:00Added an answer on June 17, 2026 at 7:31 am

    The first code snippet reads textual representation of doubles and converts them. That’s what *scanf family of functions does.

    Example valid input:

    1.0 2.7182818 3.14159265358
    

    The second code snippet reads some (probably 24) bytes from a file, without parsing or conversion. You didn’t show how you extract doubles from your buffer. Something like *(double *)buffer (to get the first value) would be expected, and it would be right (modulo alignment issues, but it’s irrelevant for your platform) if you have a “dump” of 3 platform-specific doubles in your file, created with appropriate fwrite or _write.

    Example valid input (hex dump, assuming 64-bit IEEE floats):

    00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00
    

    (If you were using POSIX read, here would be a warning on the possibility of short reads. However, _read and _s_open suggest Microsoft CRT, and it doesn’t do short reads in binary mode unless the end of file is reached).

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

Sidebar

Related Questions

I am trying to read data from a file stream as shown below: fileStream.Read(byteArray,
I'm trying to read data from an xml file and display it in a
I'm trying to read the data from a file that I've saved. This code
I'm trying to read data from a binary file and put it into a
I'm trying to read the data from an XML file, validating it against the
I was trying for the first time to read data from a file, a
I'm trying to read the binary data from a binary file with the code
I'm trying to read in some sample data from an XML file in a
I am trying to read from a file and encrypt the data using AES
I'm trying to display image data read in from a binary file (I have

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.