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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:36:06+00:00 2026-05-12T23:36:06+00:00

I have a bitmap image that I am parsing and I need to be

  • 0

I have a bitmap image that I am parsing and I need to be able to open the file and store the first unsigned short.

I tried to accomplish this using FILE and fscanf() but fscanf() always fails and returns 0 (number of items successfully read).

FILE *pFile = fopen ( fileName->c_str() , "r" );

if ( pFile == NULL )
{
    cerr << "couldn't open file ; exiting..." << endl;
    exit(0);
}

unsigned short seed;
fscanf (pFile, "%hu", &seed);

Does anyone know of another approach I could take (possibly ifstream?) or maybe could just give me some pointers? Any help would be greatly appreciated.

Thank you.

  • 1 1 Answer
  • 1 View
  • 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-12T23:36:07+00:00Added an answer on May 12, 2026 at 11:36 pm

    Don’t use the formatted functions like *scanf; they expect character representations of the data, the complement of the *printf functions which translate values into character representations.

    unsigned val;
    f = fopen (filename, "rb");
    if (fread (&val, 1, sizeof (val), f) != sizeof (val))
        // error
    

    The biggest caveat of this is how the file was written. If the endianness of the writer is different than the computer this runs on, then explicit endian code should be used instead:

    unsigned val;
    unsigned char buf[2];
    f = fopen (filename, "rb");
    if (fread (buf, 1, sizeof (buf), f) != sizeof (buf))
        // error
    else {
    //  val = (buf [0] << 8) | buf [1];   // for big endian written file
        val = (buf [1] << 8) | buf [0];   // for little endian written file
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a image/bitmap (I can make it either) in c++ that I need
I have a Base64 String that represents a BitMap image. I need to transform
In my project I have an bitmap image. I need to convert this picture
I have a chart (in bitmap format) that I'm trying to render to a
I have a function that takes some bitmap data and returns a UIImage *
I have an android application that parses some HTML, downloads an image, and displays
I have a Silverlight app that has to load an image dynamically, depending on
I am Trying to add an image to an existing button..I have done that
I am new to iPhone. What I need is I have to get image
I am trying to extract the palette from a 5-6-5 (16bit) bitmap image that

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.