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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:42:45+00:00 2026-05-27T16:42:45+00:00

Okay so I am trying to make a histogram from a three dimensional array

  • 0

Okay so I am trying to make a histogram from a three dimensional array of int in c.
Here is the line where I edit the array;

buckets[(int)floor(x/splits)][(int)floor(y/splits)][(int)floor(z/splits)]++;

x, y, z were generated earlier in the program (this is in a loop) splits was asked as input from the user. Then I try to put this data into a histogram and the compiler is giving me an illegal instruction.

histogram[(int)buckets[i][j][k]]++;

I am pretty sure it is here because I put print statements in the program which worked until this point but not afterwords. Here is all of the relavent code.

    ff=fopen(fname,"r");
int buckets[split][split][split];
splits = (double) 1/split;
for(i=0; i<split; i++){
    fscanf(ff,"%lf",&x);
    fscanf(ff,"%lf",&y);
    fscanf(ff,"%lf",&z);
    buckets[(int)floor(x/splits)][(int)floor(y/splits)][(int)floor(z/splits)]++;    
    fclose(ff);  
}
int histogram[10];
for (i=0; i<split; i++) {
    for (j=0; j<split; j++){
        for(k=0;k<split;k++){
            histogram[(int)buckets[i][j][k]]++;
        }
    }
}
  • 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-27T16:42:45+00:00Added an answer on May 27, 2026 at 4:42 pm

    When you define your array:

    int buckets[split][split][split];
    

    You do not initialize it with something like:

    memset(buckets, 0x00, sizeof(int) * split * split * split);

    So buckets has unknown values in it. You then increment these numbers, but when you do:

    histogram[(int)buckets[i][j][k]]++;

    buckets[i][j][k] could be equal to anything. Solution is to add the memset() after the array declaration.

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

Sidebar

Related Questions

Okay I have been racking my brain trying to build a JSON array from
Okay so I'm trying to make a little gag program that will run away
OKay I don't use actionscript and trying to help my friend edit a flash
Okay, here's what I'm trying to do: I'm trying to use PHP to develop
Okay, Here is what I'm trying to do... Right now it is compiling but
Okay so here is the deal. As the question states, I'm trying to POST
Okay i'm trying to make ChucK available in exported Processing sketches, i.e. if i
Okay, so I'm trying to make a game that uses this algorithm: http://www.codeproject.com/Articles/15573/2D-Polygon-Collision-Detection But
Okay I am trying to make minecraft mods using eclipse. I used this video
Okay so I'm trying to make a file browser program, and I'm in the

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.