arrays

C simple array access comparison

int isEmpty(char x [1000]){ int i = 0; while( x[i] == " " || x[i] == "/t" || x[i] == ""){ i++; } if (i != 999) return 1; } return 0; } The errors I recieve: warning: comparison between pointer and integer warning: comparison with string literal results in unspecified behavior I realise my c...

Sort 2d array into 3d array PHP.

I'm trying to figure out how to sort a 2d array into a 3d array in PHP. The array contains tasks from users in a management tree and is currently arranged like so: Array ( [0] => Array ( [Title] => Test Task [Author] => 5 [DateIn] => 2010-09-15 [Deadline] => 2010-09-30 [Position] => 1 [Description] => This is a test task [Assignee] => 3...

Bash creating array's dynamically from a parsed string

I am trying to create nested array's dynamically from a string that has been parsed (parameter expansion) using a for loop in bash and I am failing: user@server:/home/user> foo=one,two,three user@server:/home/user> for i in ${foo//,/" "}; do echo ${i}; done one two three user@server:/home/user> for i in ${foo//,/" "}; do declare -a ${i}...

While-Loop works but not the if statement?

I have this while loop in xcode. The loop seems to work fine since I printed my i++ in console. But for some reason it only checks my IF statement the first time around. I can only add one title into the MutableArray called sectionZeroTitleArray. I have many arrays in this loop so it might get confusing. I will try my best to explain. ...

Jquery slider - having name/value pairs or array for the values

I'm using a slider so that users can select their place in a range from 1-10 (or a similar range) I know that i can specify the values/steps for the slider but can i have those values correspond to another? i.e. 1 = id3040 2 = id0290 3 = id3782 So if they select '3' on the slider, I can get that corresponding value? I have a surve...

removing duplicate entries from multi-d array in python

I have a 2-d array xx=[[a,1],[b,2],[c,3]] Now I'm trying to remove duplicate entries from it. For simple 1-D array, simple code like xx=list(set(xx)) would work. But trying set on 2-d elements gives an error temp = set(xx) TypeError: unhashable type: 'list' One workaround would be to serialize xx elements, and then do a list(se...

Cannot use [] for reading

In one of my scripts, I try to do the following $data[] = self::get($row['sr_id']); // <-- line 55 However, PHP does not allow me to do this, giving me this error Fatal error: Cannot use [] for reading in /file.php on line 55 The self::get function return either a bool, or an object. Edit: The get function creates a new object whi...

In C, why is an array reference a += 2; invalid code

From my lecture slides, it states: As illustrated in the code below an array name can be assigned to an appropriate pointer without the need for a preceding & operator. int x; int a[3] = {0,1,2}; int *pa = a; x = *pa; x = *(pa + 1); x = *(pa + 2); a += 2; /* invalid */ Why is a += 2; invalid? Can anyone help clarify...

C# getting all colors from Color

I want to make a ComboBox filled with all the colors from System.Drawing.Color But I can't seem to collect all the colors from that collection I've already tried using a foreach to do the job like this: foreach (Color clr in Color) { } But all I get is an error. So how can I loop trough all the colors? Any help will be ...

Is there a PHP function for imploding an associative array without loosing the keys?

Question asks itself ^ I've heard I can mimic this using http_build_query, but I'd rather use a function that's meant for this. Thanks for replies input example: $assoc = array( "fruit" => "banana", "berry" => "blurberry", "vegetable" => "lettice" ); output wanted: (i get this with http_build_query) string(46) "fruit...

Cast Array to Object Array

I have such method which accept jagged array of Objects. public void MyDataBind(object[][] data) I use it like this GoogleChart1.MyDataBind(new[] { new object[] { "September 1", 1 }, new object[] { "September 2", 10 } }); The question would be how to pass/cast predefined array values to this method? Let's say I have two arrays belo...

How to convert a matrix to a 1 dimensional array in R

Hi I have a matrix file that is 32X48 and I want to put all of the values into a single dimensional array in R. Right now I am only able to get the last row of data. trgtFN_intensity <- "1074_B09_1- 4_5mM_Xgal_7d_W.cropped.resized.grey.png.red.median.colony.txt"; read.table(trgtFN_intensity, sep="\t") -> tmp_int maxrow_int <- nrow(...

ARM Assembly: How to pass and make use of a array of pointers inside an ARM Assembly function

Hi, I have a C function in which I have 4 pointers and each of them point to different locations of a large 2D array of floats. Because the ARM assembly functions can only be passed with 4 parameters (r0 - r3), I'm not able to understand how to pass the pointer to my return value, which will become the 5th parameter to my assembly func...

Zend_Soap : How to define return type struct in doc block?

I have a Web service set up using Zend_Soap, and some public methods in that Web service. The fact is i want to return a complex type. For instance, if i want to return a bidimensional array, like a rowset of a table how should i specify the doc block? This is one of my cases. I want to return an array each element having an int and two...

Bash echo all array members when array is referenced as a variable in a loop

The "echo" below is failing and I am too retarded to figure out why. I am simply trying to echo all of the array members in my loop. #!/bin/bash foo=bar1,bar2 for i in ${foo//,/" "} do declare -a ${i}='(null null null null)' echo ${i[*]} done Thanks for any help! ...

Iterate over a array and returning the next and the element before current.

How may i fetch next and before current element from array while iterating array with each. array.each do |a| # I want to fetch next and before current element. end ...

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...

C#: Limit the length of a string?

Hi there. I was just simply wondering how I could limit the length of a string in C#. string foo = "1234567890"; Say we have that. How can I limit foo to say, 5 characters? ...

Bash for loop if statement array name referenced as variable

The if [ {$i[0]} = "true" ] below is failing. I can't seem to figure out how to get the correct formatting for {$i[0]} in the if statement. #!/bin/bash foo=bar1,bar2 for i in ${foo//,/" "} do declare -a ${i}='(true null null null)' done for i in ${foo//,/" "} do if [ {$i[0]} = "true" ] then echo "yes" eval "echo \${$i[*]}" else echo "...

Store array in database using Ruby on Rails

ive got an array that has three values; crime, drama, thriller. Im trying to loop through each value and save it to the database. How do i extract a name from the array and save it in the database. ...