arrays

Replace string characters from array.

I have a string (of undertermined length) that I want to copy a lot of times replacing one character at a time from an array (of undertermined length) of characters. So say I have this string: 'aa' And this array: ['a', 'b', 'c', 'd'] after some magic for-looping stuff there would be an array like: ['aa', 'ab', 'ac', 'ad', 'ba', 'bb'...

Access PHP array element with a function?

I'm working on a program that uses PHP's internal array pointers to iterate along a multidimensional array. I need to get an element from the current row, and I've been doing it like so: $arr[key($arr)]['item'] However, I'd much prefer to use something like: current($arr)['item'] // invalid syntax I'm hoping there's a function out ...

Best way to store multi-dimensional array on a server?

I'm developing a web-based, turn-based strategy game which takes place on a 10x10 board. Each tile represents an area of land and has its own set of statistics (eg, income, population, fertility, natural resources). Each time the client loads it will download all of the information for the game (ie, loading the stats of only one tile i...

initialize two dimensional array of pointer elements using memset

Hi, I have a these structures definitions typedef struct my_s { int x; int y; } my_T; typedef struct your_s { my_T * x; } your_T; your_T array[MAX_COL][MAX_ROW]; To initialize the array's pointer to NULL, can I do: memset (array, 0, sizeof(array)) this does not look right to me,,, appreciate some advise. Thanks ...

How do arrays in JavaScript work ? (ie without a starting dimension size)

I was reading this post the other night about the inner workings of the Array, and learned a lot from the answers posted, especially from Jonathan Holland's one. So the reason you give a size to an array beforehand is so that space will need to be reserved beforehand, so that elements in the array will be placed next each other in memor...

C++ associative array with arbitrary types for values

What is the best way to have an associative array with arbitrary value types for each key in C++? Currently my plan is to create a "value" class with member variables of the types I will be expecting. For example: class Value { int iValue; Value(int v) { iValue = v; } std::string sValue; Value(std::string v) { sValue ...

incrementing array value with each button press?

Hi, I am building a calculator in C#. I am not sure what the best way is to have it increment a number in an array every time the button is pressed. Here is one of my current button event handler methods: //Assign button '2' to 2 with array address of 1 private void num2_Click(object sender, EventArgs e) { numbers[1...

Proper usage of array as field member in VB 2005

I normally use C# and I'm attempting to convert a qbasic programmer to the joys of object oriented programming by easing him into VB 2005. Below is a extremely simplified version of what I'm trying to accomplish. It successfully compiles, but all members in the array of card objects are set to "Nothing". The test line throws a NullRef...

C++ Returning and Inserting a 2D array object

I am trying to return an array Data Member from one smaller 2D Array Object, and trying to insert the array into a larger 2D array object. But when attempting this, I came into two problems. First problem is that I want to return the name of the 2D array, but I do not know how to properly syntax to return 2D Array name. This is what my...

How do I pass a reference to a two-dimensional array to a function?

I am trying to pass a reference to a two-dimensional array to a function in C++. I know the size of both dimensions at compile time. Here is what I have right now: const int board_width = 80; const int board_height = 80; void do_something(int[board_width][board_height]& array); //function prototype But this doesn't work. I get this e...

C++ Inserting 2D array Object into another

This problem is a continuation of a previous problem: http://stackoverflow.com/questions/402432/c-returning-and-inserting-a-2d-array-object and it is highly recommended to view the link to understand the following. I followed through Adam Rosenfield's answer and it solved the first two problems. However the last problem is not yet to ...

Can someone explain this C++ notation?

if (vector1.x > ((float*)&vector1)[j]) Is j simply just an index into the vector? e.g. is C++ able to retrieve these values using array notation even though vector isn't an array? If so I'm guessing it achieves this by referencing vector by its address? ...

How can I pass an "array" of values to my stored procedure?

I want to be able to pass an "array" of values to my stored procedure, instead of calling "Add value" procedure serially. Can anyone suggest a way to do it? am I missing something here? Edit: I will be using PostgreSQL / MySQL, I haven't decided yet. ...

.NET Rectangular Arrays: how to access in a loop?

Basically you have two ways for doing this: for (int x = 0; x < UPPER_X; x++) for (int y = 0; y < UPPER_Y; y++) { arr1[x, y] = get_value(); arr2[y, x] = get_value(); } The only difference is what variable to change in the inner loop: first or second. I heard that the results differ from language to ...

Passing Pointer To An Array Of Arrays Through Function

Hi There is a pointer-to-an-Array of Arrays i.e. NameList in the code. I want the contents of each of the Arrays in the Pointer(NameList) to get printed one by one. The below code is not able do the task. Pls. help. int Data1[] = {10,10}; int Data2[] = {20,20}; int Data3[] = {30,30}; int *NameList[] = {Data1, Data2, Data3}; main()...

Array slices in C#

How do you do it? Given a byte array: byte[] foo = new byte[4096]; How would I get the first x bytes of the array as a separate array? (Specifically, I need it as an IEnumerable<byte>) This is for working with Sockets. I figure the easiest way would be array slicing, similar to Perls syntax: @bar = @foo[0..40]; Which would return ...

Fastest way to implode an associative array with keys

I'm looking for a fast way to turn an associative array in to a string. Typical structure would be like a URL query string but with customizable separators so I can use '&amp;' for xhtml links or '&' otherwise. My first inclination is to use foreach but since my method could be called many times in one request I fear it might be too slo...

Simplest way to print an array in Java

What's the simplest way of printing an array of primitives or of objects in Java? Here are some example inputs and outputs: int[] intArray = new int[] {1, 2, 3, 4, 5}; //output: [1, 2, 3, 4, 5] String[] strArray = new String[] {"John", "Mary", "Bob"}; //output: [John, Mary, Bob] ...

C# How do I append the previous item in array to the next item in the array for unknown number of items?

How do I append the previous item in array to the next item in the array for unknown number of items? Here is what I'm trying to do. I have a string containing an LDAP path such as "OU=3,OU=2,OU=1,DC=Internal,DC=Net", I want to create each container in the above LDAP path so from the above string I need to create an array with the conte...

Convert an array into an index hash in Ruby

Let's say I have an array, and I want to make a hash so I can quickly ask "is X in the array?". In perl, there is an easy (and fast) way to do this: my @array = qw( 1 2 3 ); my %hash; @hash{@array} = undef; This generates a hash that looks like: { 1 => undef, 2 => undef, 3 => undef, } The best I've come up with in Ruby ...