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

The Archive Base Latest Questions

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

How can I convert short int[] to char*? short int test[4000]; char* test2; I

  • 0

How can I convert short int[] to char*?

short int test[4000];
char* test2;

I tried this:

test2 = (char*)test[4000]

Error–> PTR is not valid

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

    So you have a buffer in form of an array, and you want to write the binary contents of it into a file. You do it like this:

    if (fwrite(test, sizeof(test), 1, f) < 1)
    {
        // handle error here (write failed)
    }
    

    fwrite() function is used to write binary data to files (and fread() to read). It takes a void* pointer, so it can work with any type (and C++ implicitly converts any other pointer/array to it).

    The sizeof(test) determines the exact size of the array. If you don’t want to write the whole of it (i.e. just filled part of it), you want to use sizeof(short) * N, where N is the number of filled elements.

    1 here means that there is one block of data to write; so fwrite() will write the whole data at once. f is the file you’re writing to. And it returns the number of blocks written (so 1 on success and 0 on failure).


    For completeness, I should note that’s only one of the approaches to use of fwrite(). It may be a bit more semantic to use something like:

    fwrite(test, sizeof(short), N, f)
    

    but then the fwrite() may actually write only part of the data, and you will need to care about that. In other words, if it returned less than N, you’d have to retry writing the remaining part.

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

Sidebar

Related Questions

You can convert a negative number to positive like this: int myInt = System.Math.Abs(-5);
I'm not sure what Bjarne meant with this exercise: Convert the desk calculator to
How can I store an Objective-C++ short int like the one below in an
this is my short code class A { public: int x,y; A(int a=0, int
I am trying to convert as following: bool foo(int a, unsigned short b) {
I know a quick way to convert a byte/short/int/long array to ByteBuffer, and then
How can I convert a short (2 bytes) to a byte array in Java,
I would like to know how I can convert a short ASCII string to
I have to use all this and display all of them SELECT CONVERT(INT,cast(reverse(substring(char_data, 263,
Here is a much more short version of my code: char token[256]; unsigned int

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.