arrays

Implementing a generical 'map' function over arrays in C

Hi! I'm having difficulties implementing a generic 'map' function over arrays. I started with the following draft: void MapArray(void * src, void * dest, void * (f)(void *), size_t n, size_t elem) { unsigned int i = 0, j = 0; void * temp = malloc(elem); for(i = 0; i<n, i++) { temp = (f)((char *) src) + i)); for...

array of special characters to replace in a text, php, json

I have a huge text that i keep getting in a json format. When i receive them in json, for some special characters like ' " &copy, i receive them differently. i am using php and json to convert json into html. for example, i receive ' as \c101d (single quote) " as \c201d (opening quote) " as \c202d (closing quote) I am planning to keep ...

In Perl, how can I join elements of an array after enclosing each element in brackets?

I was trying to join elements of a Perl array. @array=('a','b','c','d','e'); $string=join(']',@array); will give me $string="a]b]c]d]e"; Is there anyway I can quickly get $string="[a][b][c][d][e]"; ? ...

Python "Value Error: cannot delete array elements" -- Why am I getting this?

Hi Everyone, I would really appreciate some help on this issue, I haven't been able to find anything about this value error online and I am at a complete loss as to why my code is illiciting this response. I have a large dictionary of something like 50 keys. The value associated with each key is a 2D array of many elements of the form...

I'm having difficulty populating a two dimensional array with random Boolean values and then reading those values back out in JavaScript.

I'm working on a really simple cellular automata program in JavaScript. For right now I just want to write a bunch of random Boolean values to a two-dimensional array and then read that array back to be manipulated or displayed in some way. var dimension = 5; var grid = new Array(); for (x = 0; x < dimension; x++) { grid[x...

How do I get sum of value based on same key until some point in an array?

I have an array as following. I order that array by the value of the key "attack". Everything is ok until then, but I want to get for example only 9 of that total attack values are summed up: I want to sum up 3 of key1 (3 * 45), 4 of key3 (4 * 35) and 2 of key2 (2* 25) are automatically summed up. I would be greatly appreciated if somebo...

MongoDB + PHP Item wont remove()?

I'm not sure what I'm doing wrong, but with MongoDB and PHP i'm trying to do this: $db->textures->remove(array("_id"=>$_GET['texture_id']),array("safe" => true)) But nothing happens. I did a print_r and it says: Array ( [err] => [n] => 0 [ok] => 1 ) ...

1 bit per bool in Array C++

bool fp[81]; From my understanding fp should use ceil(81/8) bytes because it is in succession. Am I correct? How can I prove this? ...

Dynamic array instead of static when creating ListView icons and text Android

Hi, I am using this following code which creates a ListView with text and an icon but the problem that I have which the following I want the array to be dynamic instead of static so my list gets created dynamically not statistically. My ultimate goal is to retrieve specific strings from my Db and to display it then on the Listview where...

SQL IN operator in the WHERE clause

The following query: SELECT SUM (peak_power) FROM t_mpi_pv WHERE info_id IN ( SELECT mp_info_id FROM t_mp WHERE mp_id IN ( ARRAY[29800001,29800008,29800015,29800022,29800029] ) ) Doesn't work. I get the error: "Operator does not exist: integer = integer[]". But SELECT SUM (peak_power) FROM t_mpi_pv WHERE info_id IN ( SEL...

How to find first/second element of associative array when keys are unknown?

In PHP when you have an associative array, e.g.: $groups['paragraph'] = 3 $groups['line'] = 3 what is the syntax to access the first or second element of the array when you don't know the value of the keys? Is there something like in a C# LINQ statement where you can say: $mostFrequentGroup = $groups->first()? or $mostFrequentGro...

Convert serialized string from PHP to array in AS3.0

Hi there I'm busy communicating with my Flash file with a PHP script which in turns communicates with my db, I need to pass an array from PHP back to Flash, which happens correctly I assume, but I'm unable to unserialize the string correctly when it returns, my string looks like this: memberNum=2&success=1&teamMemberID%5B0%5D=1&teamMem...

Objective C: What is the best way to create and use a dynamic boolean array?

I have been struggling with the best way of creating, accessing and updating values from a dynamic boolean array for more than a week now. @interface myDelegate : NSObject { NSMutableArray *aShowNote; } @property (nonatomic, copy) NSMutableArray *aShowNote; This is how I have initialised my array: NSMutableArray *aShow = [[NSMutab...

Java: how declare an array and quickly fill its with data?

Hi all. public static void main(String[] args) throws IOException { String st3[]=new String[]{"сто", "двести", "триста", "sdf", "sdfsd", "sdfsd"}; System.out.println(st3[1]); } In second line Netbeans displays an error: "non-static variable cannot be referenced from a static context". I know that the problem is in declari...

array comparison for multiplication & subtraction

I have two big numbers (type int) which are stored in array with a size at least 1000, and I want to compare these two numbers to get information which one is bigger than the other. How can I do this? Actually , I will do two things subtract these two multiply these two (I am studying in this topic, indeed, and I didn't find an effi...

Perl: find if a variable's value matches that in an array

I'm a perl newbie. I have a code in which a variable is loaded with several values during a foreach loop. What I want to do is to perform some operation on that variable only if its in that array. What is the most efficient way to do this in perl as the data I am working on is very large. A simple example of my question is, say I have a...

JavaScript access string chars as array

Hello! Is it ok to do this: var myString="Hello!"; alert(myString[0]); // shows "H" in an alert window Or should it be done with either charAt(0) or substr(0,1)? By "is it ok" I mean will it work on most browsers, is there a best practice recommandation that says otherwise etc. Thank you. ...

Multiplication of two extremly large integers in array

Multiplication of two integers, like a = 38473847837483473894283749832938293872389472847389243847347 b = 92892382019283923829302392830923890 stored as a[0] = 3, a[1] = 8 ... I want to multiply these two over using efficient algorithm (note I stored them in array A and array B). And I want store result in RES[]. How can I do, ...

vb.net handle a post with an array

Hello All, I'm trying read an array that was post from a html form <input name="test[]" id="1" type="checkbox" value="1" /> <input name="test[]" id="2" type="checkbox" value="2" /> <input name="test[]" id="3" type="checkbox" value="3" /> <input name="test[]" id="4" type="checkbox" value="4" /> In php I know you can just access the da...

How to make arrays of button in vb .net 2005

hi there :) i just want to ask on how to make an array of buttons in vb .net 2005. It seems very different in vb6 'coz in vb6 you have just to add an index on its property but in vb.net there is no index property. Can it be made by designing in on the form just like copying and pasting on the form in vb6? ...