arrays

Difference between char *str="STRING" and char str[] = "STRING" ?

Hello, While coding a simple function to remove a particular character from a string, I fell on this strange issue: void str_remove_chars( char *str, char to_remove) { if(str && to_remove) { char *ptr = str; char *cur = str; while(*ptr != '\0') { if(*ptr != to_remove) { ...

Is array of Object possible in Objective C?

I'm quite new to objective-c. I have problems when creating array of objects. In java it is possible to make array of object and can access individual instances directly. For example, SomeClass[] instance = new SomeClass[10]; instance[i].var=10; Is there any way to do like this in objetive-c? Can I access the instance variable in ar...

Array to one level higher

I have this array: [@attributes] => Array ( [url] => [navigation] => true [template] => home ) [@children] => Array ( [0] => Array ( [name] => H...

Need to split arrays to sub arrays of specified size in Ruby

Hi, I have an array something like this, arr = [4, 5, 6, 7, 8, 4, 45, 11] I want a fancy method like sub_arrays = split (arr, 3) This should return me [[4, 5, 6], [7,8,4], [45,11]] ...

Array copy fails in loop

Simplified Question: I want to use the following to build an html table dynamically. //table.Rows[row].Cells.AddRange(new TableCell[] { new TableCell(), new TableCell(), new TableCell(), new TableCell(), new TableCell(), new TableCell() }); for (int row = 0; row < intRows; row++) { table.Rows.Add(new TableRow()); table.R...

How can I add repeated values to an array in Perl?

I have an array @genotypes = "TT AG TT AG...." and want to add a spike to it (e.g. 20 x TT) to make a new array. I can obviously push "TT" into the array 20 times - but is there a simpler way of doing this? (ie. not @newarray = push @genotypes ("TT", "TT", "TT",......20 times!); ...

Android Sharepreferences and array

Hello, I created a weather widget. I store its configuration in sharedpreferences. The widget is updated by a service. I keep the weather information together with forecasts in an array. After the phone is off for the night i find that the array values are gone,maybe the system suspended? the service. Is there a way to store the array in...

How can I create arrays and hashes in Perl?

This is not generic question. I have asked this question because I'm confused with creating Perl arrays. How do I create or define the Array or hash? What are other ways to do that? How do I clear a array or hash? What are other ways to do that? How do I create a array or hash with empty element? What are the ways to create hash with...

Error: Generic Array Creation

I don't understand the error of Generic Array Creation. First I tried the following: public PCB[] getAll() { PCB[] res = new PCB[list.size()]; for (int i = 0; i < res.length; i++) { res[i] = list.get(i); } list.clear(); return res; } Then I tried doing this: PCB[] res = ne...

Ruby - test each array element, get one result

I want a one-liner to return true/false, that tests each element in an array for whether it's an Integer or not. So if any element in the array is not an Integer, it should return false, else true. Here's my try: >> ([2,1,4].map {|x| (x.is_a? Integer)}).reduce {|x, result| x and result} => true >> ([2,"a",4].map {|x| (x.is_a? Integer)})...

Printing a new array of primes from a random array?

Hy there i a beginner in java started 3 weeks ago, im having some problems with this code. in the main method i have an array containing 10 elements. i've already made several methods to like public static void println(int[] array) ------ to print and array public static boolean isPrime(int el) ----------- prime test. returns tru...

PHP & Array question

Hey Guys, I have an array called $array_all; This array will always have 3 possible values: 1, 1,2, 1,2,3, I created a string from the array while in a foreach loop and concatenated a comma at the end. So, now I have a nice string that outputs the exact value the way it should. 1,2,3, I can copy this output from my browser and i...

Possible to return a String array

Is it possible to make a method that returns a string [ ] in java???? ...

How can I find the value of the first element in an associative array in PHP?

I have an array like this: $array = array( 'fruit1' => 'apple', 'fruit2' => 'orange', 'fruit3' => 'grape', ); Is there a function that'll grab 'apple' (the first key) from that array? Or do I have no choice but to do this? function firstkey($array) { for($array as $first) { return $first; } } ...

beginner question, calling a function/assign property etc... of an object inside an array

So if I create an object test, and it has a property color. When I add this object to an array list I typically can access this using myarray(0).color but intellisense doesn't 'know' that I have a 'test' object inside the array. It would let me type myarray(0).whatever but would then crash if I made typo. It seems like I should be able t...

C#: Altering values for every item in an array

I'm wondering if there is built-in .NET functionality to change each value in an array based on the result of a provided delegate. For example, if I had an array {1,2,3} and a delegate that returns the square of each value, I would like to be able to run a method that takes the array and delegate, and returns {1,4,9}. Does anything lik...

PHP / HTML - Generate a html list from a array

Hi I have a array like ('mary', 'johnny', 'butch', 'pony', 'katy', 'chuck', 'norris') The number of elements can vary... How can I build a nice list from all these elements, like this: <ul> <li> Mary Johnny Butch </li> <li> Pony Katy </li> <li> Chuck Norris </li> ? Basically build the list ...

PHP multidimensional array

Here's a quickie for the pros: How do I display Value 1, 2, 3 etc as it's in it's third array? $meta_boxes = array ( "checkbox" => array ( "name" => "checkbox", "title" => "", "description" => "This is an example of a checkbox field.", "type" => "checkbox", ...

Jquery $.post array (again...)

So, somewhat standard situation: OK, so replacing <div> with <form> works. Now to see if any nesting issues occur... <div id=hidden> <input type=hidden value=2 id=i1 name=i1> <input type=hidden value=5 id=i2 name=i2> <input type=hidden value=6 id=i3 name=i3> <input type=hidden value=1 id=i4 name=i4> <input type...

How do you get the size of array that is passed into the function?

I am trying to write a function that prints out the elements in an array. However when I work with the arrays that are passed, I don't know how to iterate over the array. void print_array(int* b) { int sizeof_b = sizeof(b) / sizeof(b[0]); int i; for (i = 0; i < sizeof_b; i++) { printf("%d", b[i]); } } What is the b...