arrays

Why no "realloc" seems necessary when allocating new element to a char pointer?

I'm trying to create a pointer to char pointer to which I can easily add new elements (strings). I use malloc to create the first 2 dimensions and realloc when I want to add new items. I wrote code with and without realloc and I'm getting the same results. Is this an expected/normal behavior? With realloc: char **p; // create poin...

Python Array with String Indices

Is it possible to use strings as indices in an array in python? For example: myArray = [] myArray["john"] = "johns value" myArray["jeff"] = "jeffs value" print myArray["john"] ...

Convert String to int array

I have an int array that holds a single digit in each index so that once printed out, it displays a long number. Ex: digit = {1, 2, 3, 4, 5} would look like 12345. I have a method that takes a string as parameter and puts the numbers it gets from the string into the digit array. It looks like this: digit = new int [50]; for (int i =...

Is unsigned char a[4][5]; a[1][7]; undefined behavior?

One of the examples of undefined behavior from the C standard reads (J.2): — An array subscript is out of range, even if an object is apparently accessible with the given subscript (as in the lvalue expression a[1][7] given the declaration int a[4][5]) (6.5.6) If the declaration is changed from int a[4][5] to unsigned char a[4]...

need help grouping a php array

hi all, i've got a mysql query which spits out the following array: Array ( [0] => stdClass Object ( [item1] => foo 0 [item2] => bar 0 [catid] => 3 ) [1] => stdClass Object ( [item1] => foo 1 [item2] => bar 1 [catid] => 7 ) ...

JavaScript filtering an array of <input> values by character count

This should be a quickie, but I'm scratching my head as to why this bit of JavaScript isn't working for me. The goal is to take the value of an input box (string of words separated by spaces), list these words as items in an array, and remove those which are fewer than 3 characters: var typed = $('input').val(); var query = typed.split(...

What's the cause of my segmentation fault?

I'm trying to write a program that reads in entries from a file into a dynamically allocated array of structures using input redirection. My program compiles fine but I'm getting a segmentation fault and I'm having trouble finding the cause. Here's my Program: #include <stdio.h> #include <stdlib.h> #include <string.h> typedef str...

Java Generic Primitive type n-d array

I have to pass a primitive 2d array to a filtering routine.The algorithm for filtering(median filter) is same irrespective of the type of the array.Is there a way to pass any type of array in a generic manner or should I overload the same same function with different array types.In the second case the same code will have to be repeated f...

How to remove duplicate values from an associative array based on a specific value?

Hi there! I have an array that looks just like that: array(3) { ["fk_article_id"]=> string(1) "4" ["first_name"]=> string(6) "Ulrike" ["last_name"]=> string(10) "Grasberger" } array(3) { ["fk_article_id"]=> string(1) "9" ["first_name"]=> string(5) "Frank" ["last_name"]=> string(9) "Neubacher" } array(3) { ["fk_article_id"]=> string(3...

php recursion level

Hello! I have the recursion function. There are an hierarchy users structure. I send a user id to my function and it should find all user under this. Function returns an array of all associates users. My task is to find a levels of this users. For example: User1 / \ User2 User3 / \ \ User4 User5 User6...

Organizing and building a numpy array for a dynamic equation input

I'm not sure if my post question makes lots of sense; however, I'm building an input array for a class/function that takes in a lot of user inputed data and outputs a numpy array. # I'm trying to build an input array that should include following information: ''' * zone_id - id from db - int * model size - int * type of analysis - o...

NSArray and bool values

Can an NSArray hold an array of bool values? The following code runs BOOL b = NO; NSMutableArray *array = [[NSMutableArray alloc] init]; [array addObject:[NSNumber numberWithBool:b]]; NSLog(@"value is %d", [array objectAtIndex:0] ); However, I don't get a value of 0 for NO as expected. Instead, this is what I get value is 3773...

Putting WinForm Labels Into An Array?

Let's say I have Label1 Label2 Label3 I want to do something like: for(int i=0;i<3;i++) { LabelArray[i].Text = "weee!"; } To populate the array, I know I can do something like: LabelArray[0] = Label1; LabelArray[1] = Label2; LabelArray[2] = Label3; But that doesn't seem smart just because I have 50 labels, and that would be...

PHP: can one determine the parent array's name and key from a reference to an array element?

let's assume we have an array like this $arr=array(array('a'=>1,'b'=>2),array('c'=>3,'d'=>4)); and a reference to one of its elements $element=&$arr[1]['c']; My question is is it possible to get back to the original array using the reference alone? That is to get back to the parent array in some way without knowing it by name... Th...

What is difference when we type static content of a multi dynamic array and we create a array of array

if i am using below static values than my code is working fine: ohlc = [[090300, 25.75, 25.75, 25.75, 25.75], [090400, 25.75, 25.75, 25.75, 25.75], [090700, 25.73, 25.73, 25.73, 25.73], [091300, 25.76, 25.76, 25.76, 25.76]]; but if i am using below code than my code is not working var labels = xmlDoc.getElementsByTagName('no...

Converting Array of Primitives to Array of Containers in Java

Is there an elegant way to turn an array of primitives into an array of the corresponding container objects -- turn a byte[] into a Byte[], for example? Or am I stuck with looping through it and doing it manually? Yeah, the for loop isn't exactly difficult. Just kinda ugly. ...

Split array into unique pairs

Say i start with a simple array (which could be theoretically of any length): $ids = array(1,2,3,4); What it the best solution for splitting this array into an array of unique pairs like: $pair[0] = array(1,2); $pair[1] = array(1,3); $pair[2] = array(1,4); $pair[3] = array(2,3); $pair[4] = array(2,4); $pair[5] = array(3,4); ...

C++: mixture between vector and list: something like std::rope?

Hi, When storing a bunch of items and I don't need random access to the container, I am using an std::list which is mostly fine. However, sometimes (esp. when I just push back entries to the back and never delete somewhere in the middle), I wish I had some structure with better performance for adding entries. std::vector is bad because...

Posting multidimensional array with PHP and CURL

Hi everyone, I'm having trouble posting form data via CURL to a receiving PHP script located on a different host. I get an Array to string conversion error This is print_r of the array I'm posting: Array ( [name] => Array ( [0] => Jason [1] => Mary [2] => Lucy ) [id] => 12 [status] => local ...

how to calculate the mode of an unsorted array of integers in O(N)?

...using an iterative procedure (no hash table)? It's not homework. And by mode I mean the most frequent number (statistical mode). I don't want to use a hash table because I want to know how it can be done iteratively. ...