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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:26:57+00:00 2026-05-24T03:26:57+00:00

Code executes, but nothing gets passed on image_data (line 44 the write_function) So I

  • 0

Code executes, but nothing gets passed on image_data (line 44 the write_function)

So I have no working array for the function (line 11), why is that so? I thought passing on the reference for image_data should be enough? (I’m used to it, mostly developing JAVA)

#include <iostream>
#include <string.h>
#include <fstream>

using namespace std;

//Expects bgra image data
//Only makes bgr and bgra with 8 bits per pixel pictures
//Expects big endian ushorts
//makes no checks on the data supplied!
void write_tga(ofstream& output,char image_data[],unsigned short xWidth,unsigned short yWidth,bool transparency) //Line 11 - Line 11 - Line 11 - Line 11
{
    char zero = static_cast<char>(0x00);
    char two = static_cast<char>(0x02);

    //Convert uint to char Array
    unsigned char xWidth_arr[2];
    unsigned char yWidth_arr[2];
    memcpy(xWidth_arr, &xWidth, 2);
    memcpy(yWidth_arr, &yWidth, 2);

    char header[18] = {zero,zero,two,zero,zero,zero,zero,zero, zero,zero,zero,zero, xWidth_arr[0],xWidth_arr[1],yWidth_arr[0],yWidth_arr[1],static_cast<char>(0x18),zero};
    //enabling transparency
    if(transparency){
        header[16]= static_cast<char>(0x20);
        header[17]= static_cast<char>(0x08);
    }
    char footer[26] = {zero,zero,zero,zero,zero,zero,zero,zero, 'T','R','U','E','V','I','S','I','O','N','-','X','F','I','L','E','.',zero};

    output.write((char*)&header,sizeof(header));
    output.write((char*)&image_data,sizeof(image_data));
    output.write((char*)&footer,sizeof(footer));
    output.close();
    cout << image_data[0] << endl;
}

int main()
{
    ofstream output("data.tga",ios::binary);
    output.seekp(0);

    char zero = static_cast<char>(0x00);
    char image_data[12] = {static_cast<char>(0xff),static_cast<char>(0xff),static_cast<char>(0xff), zero,zero,zero, zero,zero,zero, zero,zero,zero};

    write_tga(output,image_data,2,2,false); //Line 44 - Line 44 - Line 44 - Line 44
    return 0;
}
  • 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-24T03:26:58+00:00Added an answer on May 24, 2026 at 3:26 am

    What exactly are you trying to do in this code:

    output.write((char*)&image_data,sizeof(image_data));
    

    Array name is a pointer. You’re writing to output its content (the memory address), not the actual data it points to. Remove the & operator to write the content it points to, which is what you wanted, I think. Or use & on the first member (e.g.: (char*)&image_data[0]).

    sizeof returns a size of a pointer for image_data. Use a “size” parameter to convey the size.

    And you’re abusing static_cast for no apparent reason.

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

Sidebar

Related Questions

I have some Perl code that executes a shell script for multiple parameters, to
I am getting this error on a remote server, but the same code executes
This code executes handbrakecli (a command line application) and places the output into a
My application contains a piece of code that executes inside of Component Services, so
I'm interested in how java organizes memory and executes code (like what gets put
I'm working on a .NET component that gets a set of data from the
I have an android application i have been working on that downloads an image
My code is running elevated but nothing can see/execute c:\windows\system32\rstrui.exe (System Restore Point UI).
But it doesn't work -meaning the java code is not executed. Although the batch
Simple sum of digits code. It compiles but when executed, the last cout gives

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.