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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:19:54+00:00 2026-05-31T13:19:54+00:00

I am attempting to read hex values from a text file. There can be

  • 0

I am attempting to read hex values from a text file.

There can be 20000 lines each of varying length.

0F61048C

1F1ED7F855A106CB20D574C24833

52D3C74F4101FC1143C6DE298933

CF8630C79991046C587474E4B858

6EF8745D6000ACDB3757ECEB79EB

I cannot use fgets because it converts each value to ASCII while storing in memory. I am thinking of using fscanf as there is format specifier %x. But how can i read an entire line using fscanf? I know this is not a best approach to read a line. Perhaps it is fgets, but fgets converts to ASCII, i do not want to use this.
In fgets if there is hex line like, 01 04 05 FF, it stores in memory as 3031 3034 3035 4646. It is really cumbersome to convert this format back to 01 04 05 FF.

Can anybody help me with this? I am stuck with this problem for nearly 2 weeks.

  • 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-31T13:19:55+00:00Added an answer on May 31, 2026 at 1:19 pm

    You can certainly do this using fgets(), and it’s probably much easier than using fscanf() for variable length lines. For example:

    char buf[200];
    while (fgets(buf, sizeof(buf), infile) != NULL) {
        unsigned char a[200];
        int i = 0;
        while (buf[i] != '\n') {
            int b; // must use int with sscanf()
            sscanf(&buf[i], "%2x", &b);
            a[i] = b;
            i += 2;
        }
    }
    

    The above has no error checking (non-hex digits, odd number of digits on line, etc). But it’s the general idea.

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

Sidebar

Related Questions

I am currently attempting to read in Hex values from a text file. There
I'm currently attempting to read information about an object from the web.config file and
I am attempting to read in from a txt file strings that are very
Well, I am attempting to read a text file that looks like this: FTFFFTTFFTFT
I'm attempting to read values from a 2-dimensional array and multiply them to make
I'm attempting to use TinyXML to read and save from memory, instead of only
Attempting to print out a list of values from 2 different variables that are
I have a Excel .CSV file I'm attempting to read in with DictReader. All
I am attempting to read a MySQL database from my C# project using the
I'm attempting to read a value from a registry entry with Powershell. This is

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.