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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:11:27+00:00 2026-06-10T05:11:27+00:00

Suppose I have five binary files on disk. These five files encode sequences of

  • 0

Suppose I have five binary files on disk. These five files encode sequences of numbers in a binary format except they all have different types. Let’s say they are SHORT INT, INT, LONG, FLOAT, and DOUBLE. We’ll let the files also have a different number of numbers stored in them.

Now suppose I have a program that when executed, asks the user

Enter filename you wish to load:

and the user can pick one of these five files. I would like the program to load these files into an array so that further calculations may be performed.

We may assume there exist two functions: one that returns an integer value that encodes the type (i.e., SHORT INT, INT, LONG, FLOAT, or DOUBLE) of the file (call it “getfiletype”) and one that returns the number of numbers (e.g., 1000, 9338, 8131, 0, etc.) in the file (call it “getfilesize”). The actual number of entries may be billions of numbers large. If possible, within the program I would like to use the same name for the array (say “array”) that holds the values of whatever file the user picked. That way I can have blocks like

N=getfilesize("pickedfile.dat");
for(i=0 ; i<N ; i++ ) {
    doublearray[i]==2.0*(double)array[i]+7.12;
}

that can transform the array. Here I have introduced a new array called “doublearray” to hold the transformed values. This double array would then either be written to a file in format DOUBLE or converted before write to one of the other formats.

How do I do this sort of thing? Throughly confused.

  • 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-10T05:11:28+00:00Added an answer on June 10, 2026 at 5:11 am

    Your program could create a static (or global) void* array that would be populated by the latest call to either getfiletype() or getfilesize(). You would then have to appropriately cast it (as you’ve done specifically to double in your example). It is assumed you’ve solved the loading of the file data aspect.

    Although that approach is not really very clean in terms of usage (relying on a static or global would limit your options for performing different conversations – specifically as it currently stands you would have to ensure you operate in a sequential manner).

    A cleaner API would perhaps be something along these lines:

    enum TypeEnum { SHORT_INT, INT, LONG, FLOAT, DOUBLE };
    void* getfiledata(char *filename, unsigned int *size, TypeEnum *type);
    #define GET_DATA_AND_CAST(filename, array, array_size) \
        do { \
            TypeEnum type; \
            void* arr = getfiledata(filename, array_size, &type); \
            switch(type) { \
                case SHORT_INT: \
                    array = (short*)arr; break; \
                case INT: \
                    array = (int*)arr; break; \
                case LONG: \
                    array = (long*)arr; break; \
                case FLOAT: \
                    array = (float*)arr; break; \
                case DOUBLE: \
                    array = (double*)arr; break; \
                default: \
                    // ASSERT \
            } \
        } while(0)
    

    You can then use it like:

    void process_doubles(void *array) {
        double to_conv[];
        unsigned int size;
        GET_DATA_AND_CAST("pickedfile.dat", to_conv, &size);
    
        for(i=0; i<size; ++i ) {
            doublearray[i] = 2.0 * to_conv[i] + 7.12;
        }
    }
    

    IMHO C++ would make this even nicer (as you could use templates), but as this question is only tagged with C I’m just presenting options in C.

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

Sidebar

Related Questions

I have two Android applications,suppose they are A and B, A has five activities
Suppose I have a string like this: one two three four five six seven
Suppose I have a file of five lines with IP addresses: 1.2.3.4 5.6.7.8 5.6.7.8
Suppose that a product can have up to five (5) complaints. In this case,
I have five text files that are produced by an R program, (each of
I have five combo boxes. Each one has a different name, but the possible
Possible Duplicate: Code to calculate “median of five” in C# Suppose I have five
Suppose I have a folder with a few files, images, texts, whatever, it only
I have the five following strings (they are supposed to act like time): 11-20
suppose i have a .on() function wherein i select multiple ids $(#i, #am, #your,

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.