2d-array

Reallocate a 2d char array

I have following code int wordLenght = 256, arrayLength = 2, i = 0, counter = 0; char **stringArray = NULL; stringArray = calloc(arrayLength, sizeof(*stringArray)); for(counter; counter<wordLenght; counter++) stringArray[counter] = calloc(wordLenght, sizeof(stringArray)); while(1) { printf("Input: "); fgets(stringAr...

C# 2-d array concatenation

Is there a more performant way to concatenate 2-d arrays than this? static void Main(string[] args) { int[][] array1 = { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }, new int[] { 7, 8, 9 } } ; int[][] array2 = { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }, new int[] { 7, 8, 9 } }; int[][] a...

how to convert 2D binary matrix to black & white plot?

i have a 2D binary matrix that i want to convert as a plot of black and white matrix.. please how this can be done ? can you please provide me with a code? let say i have 4*2 matrix it's entry as follow: 1 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 how this can be converted to black white matrix? some of my input binary matrices are of size 100*9, ...

2D Array of UIButtons Isn't Working (Objective-C/iPhone development)

I've made a bunch of UIButtons in a grid and I want to be able to iterate over them easily so I've put them in an NSMutableArray. Like so: // in .h UIButton* button1; UIButton* button2; ... UIButton* button9; UIButton* myButtons[3][3]; // in init function in app myButtons[0][0] = button1; myButtons[0][1] = button2; ... myButtons[2]...

Algorithm for finding nearest object on 2D grid

Say you have a 2D grid with each spot on the grid having x number of objects (with x >=0). I am having trouble thinking of a clean algorithm so that when a user specifies a coordinate, the algorithm finds the closest coordinate (including the one specified) with an object on it. For simplicity's sake, we'll assume that if 2 coordinates...

Arithmetic operation so that 0, 1, & 2 return 0 | 3, 4, & 5 return 1, etc.

Hello SO community! I'm trying to take 9x9, 12x12, 15x15, etc. arrays and have the program interpret them as multiple 3x3 squares. For example: 0 0 1 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 6 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 8 0 0 0 9 Will be understood as: 0 0 ...

How to return a 2D String array in java?

I have a method wherein i have to return a 2D String array. The part of code for that method is as follow:- public String[][] retrieveData(){ try{ int noOfRows = 0; pstmt = con.prepareStatement("select * from category"); ResultSet rs = pstmt.executeQuery(); while(rs.next()) noOfRows++; rs.first(); categoryContent = new ...

Divide grid (2D array) into random shaped parts?

The Problem I want to divide a grid (2D array) into random shaped parts (think earth's tectonic plates). Criteria are: User inputs grid size (program should scale because this could be very large). User inputs grid division factor (how many parts). Grid is a rectangular shaped hex grid, and is capped top and bottom, wrap around ...

comparing Matlab vs CUDA correlation and reduction on a 2D array

I am trying to compare cross-correlation using FFT vs using windowing method. My Matlab code is: isize = 20; n = 7; for i = 1:n %%7x7 xcorr for j = 1:n xcout(i,j) = sum(sum(ffcorr1 .* ref(i:i+isize-1,j:j+isize-1))); %%ref is 676 element array and ffcorr1 is a 400 element array end end similar CUDA kernel: __global__ void xc_...

I have a 2d (n x n) string array in C#, how do I get it ouputted to a webpage dynamically (Tried DataTables/Binding, etc...).

Hello, I have an n by n String array that needs to be outputted to a web page, I have found some solutions that require many many (read: many) lines of code (usually converting it to a DataTable then binding to a GridView). And almost all of these solutions will not even work for the dynamic nature of my arrays (I do not know ahead of ...

C++: TwoDimensional Array: One dimension fixed?

Hi, I need to pass a double [][6] to a method. But I don't know how to create that two-dimensional array. 6 is a fixed size (or a "literal constant", if my terminology is right), which the method accepts. I was trying something like this, but without success... double *data[6] = new double[6][myVariableSize]; So, the method really ...

Setting a nested array in c++

I'm new to C++, and I have a question that should be easy, but it's making me crazy. I'm trying to set up a 2D array. The array is declared in Solver.h like so: protected: static const int gridSize = 9; int theGrid[gridSize][gridSize] int *boxes[gridSize][gridSize]; ... and I'm trying to initialize it in Solver::Solver() ...

Sum integers in 2d array using recursion ?

Hello! I need some help with this problem. I have to sum alle the integers in a 2d array using recursion. Below is what I have managed to do on my own, but I'm stuck. This code generates the sum 14, which should be 18. Any suggestions? Is the base case wrong? Or is the recursive method wrong? public class tablerecursion { public static...

How to create a 2d array of zeroes in javascript?

Is there an easy way to programmatically create a 2d array in javascript? What I don't want: var array2D = [ [0,0,0], [0,0,0], [0,0,0] ] ...

Defining an XML format for a 2D array (Grid) of items

I need to define an XML format and then read it in ActionScript3, which will be storing: the number of rows and columns in a grid the horizontal and vertical spacing in pixels the size of each square in the grid in pixels an optional label for each square in the grid an optional hyperlink for each square in the grid The following is ...

1-D into 2-D array

A program in c++ that accept an integer array and its size as arguments and assign the elements into a 2-D array of integers. for ex: if the array is 1,2,3 The resultant 2-D array is given by 1 2 3 1 2 0 1 0 0 ...

Beginner C++ Using accessors / getters to pull data from a private member variable (2D array)

Hi guys, total noob here with about 2 months of C++ experience (no other background) so go easy on me. I am writing a battleship game for a programming assignment. The game grid is 15X20 and I am trying to have the grid as a private member variable of the class player. My question is: If the class player has a private member variab...

Seg Fault when initializing array

Hi guys, I'm taking a class on C, and running into a segmentation fault. From what I understand, seg faults are supposed to occur when you're accessing memory that hasn't been allocated, or otherwise outside the bounds. 'Course all I'm trying to do is initialize an array (though rather large at that) Am I simply misunderstanding how to ...

Getting a very annoying segmentation fault... mallocing 2d array in C.

Hi, I'm having a little trouble with this. First of all, this is for a simple graphics library that I was writing. What I'm doing is making it possible to declare multiple "virtual screens", with dimensions of the programmer's choice. For this, I need to dynamically allocate enough memory based on the number of pixels the screen will c...

Efficient way to keep a graph (2-D array)

Hi Does anyone know a more efficient way to keep a graph information (i.e. more efficient than keeping it as 2-D array), in terms of memory space or build time? you can assume it's values are limited between 0-255. Thanx! ...