arrays

Error Showing Up in Server Logs...How Do I Stop It?

I'm getting an error and I've googled everything I can think of with barely any insights. Maybe you can help with a fresh set of eyes. I have a function that returns an array of objects. The code that calls this function then loops through this array and does what it needs to do with each object. It seems to work visually when it spits ...

The PHP function array_unique doesn't work

I have an array in PHP and I want to remove duplicates. I simply turned to the function array_unique() to create a new array and remove the duplicates. Here's the code: $unlink = array(); $unlink = array_unique($linkphoto); foreach ($unlink as $link) { echo $link, "<br />"; } Still it shows duplicates! Any suggestions about wha...

When teaching C, is it better to teach arrays before or after pointers?

For those of you with curriculum development experience: what is the best strategy regarding arrays? I have seen some schools that teach arrays after variables and control structures, often before even teaching functions. This allows teaching of some rudimentary algorithms, etc. However, it then brings the problem of how to pass arrays ...

Using variable name as array index

Hi everyone, I have few files which I put in array. I shuffle the files so that it can be displayed in random order. How to know that array index 0 is actually image1.txt or image2.txt or image3.txt? Thanks in advance. String[] a = {"image1.txt","image2.txt","image3.txt"}; List<String> files = Arrays.asList(a); Collections.shuffle(fi...

Swap key and array value pair

I have a text file layed out like this: 1 a, b, c 2 c, b, c 2.5 a, c I would like to reverse the keys (the number) and values (CSV) (they are separated by a tab character) to produce this: a 1, 2.5 b 1, 2 c 1, 2, 2.5 (Notice how 2 isn't duplicated for c.) I do not need this exact output. The numbers in the input are ord...

Array index out of bound in C

Why does C differentiates in case of array index out of bound #include <stdio.h> int main() { int a[10]; a[3]=4; a[11]=3;//does not give segmentation fault a[25]=4;//does not give segmentation fault a[20000]=3; //gives segmentation fault return 0; } I understand that it's trying to access memory allocated to pr...

How Does sizeof(Array) work

How does c find at run time the size of array? where is the information about array size or bounds of array stored ? ...

Java array problems

I have put few elements in array (e.g. 5 elements) The first element, index[0] of the array will automatically displayed without the user need to click the button. After the button clicked, it will print the next elements of array and the processes continue until the last element of array. Everytimes the button clicked, a file will be ...

Merge two arrays (key and content) in PHP

I have an array like the following Array ( [0] => "txt1" [1] => "txt2" [2] => "txt3") I have another array like it but with different content : Array ( [0] => on [2] => on) The aim is to get a final array with the keys of the second and the content of the first, it's like merging them. So that the final result is : Array ( [0] => "...

VB.NET Array Intersection

This could be terribly trivial, but I'm having trouble finding an answer that executes in less than n^2 time. Let's say I have two string arrays and I want to know which strings exist in both arrays. How would I do that, efficiently, in VB.NET or is there a way to do this other than a double loop? ...

Making a very large Java array

I'm trying to find a counterexample to the Pólya Conjecture which will be somewhere in the 900 millions. I'm using a very efficient algorithm that doesn't even require any factorization (similar to a Sieve of Eratosthenes, but with even more information. So, a large array of ints is required. The program is efficient and correct, but re...

Printing distinct integers in an array

I'm trying to write a small program that prints out distinct numbers in an array. For example if a user enters 1,1,3,5,7,4,3 the program will only print out 1,3,5,7,4. I'm getting an error on the else if line in the function checkDuplicate. Here's my code so far: import javax.swing.JOptionPane; public static void main(String...

How do I create an array in C++ which is on the heap instead of the stack?

I have a very large array which must be 262144 elements in length (and potentially much larger in future). I have tried allocating the array on the stack like so: #define SIZE 262144 int myArray[SIZE]; However, it appears that when I try and add elements past a certain point, the values are different when I try to access them. I under...

How to send array files to other class

How can i send a files which stored in array to other class? I have tried this code but isnt working. public class abc { .... String [] indexFiles = new String[100]; public abc (){ indexFiles [0]=image1.txt; indexFiles [1]=image1.txt; .... draw = new drawing (indexFiles(0)); // I got error in th...

PHP: Adding elements to empty array

If I define an array in PHP such as (I don't define its size): $cart = array(); Do I simply add elements to it using?: cartData[] = 13; cartData[] = "foo"; cartData[] = obj; Don't arrays in PHP have a add method, i.e. cart.add(13)? ...

double[,] type, how to get the # of rows?

Hi, I seem to be getting an odd value. How do I get the number of rows in my array: double[,] lookup = { {1,2,3}, {4,5,6} }; The output should be 2. ...

Sort order when using foreach on an array, list etc.

When iterating through an array using foreach, are there any guaranties that the order in which the elements are returned is the order array[0], array[1], array[2], ... I know this is how the Array class is implemented now but are there any guaranties for future versions of the framework? The same questions goes for List<>. ...

How can I convert a list<> to a multi-dimensional array?

I have the following method signature: public void MyFunction(Object[,] obj) I create this object: List<List<Object>> obj = new List<List<Object>>; Is there an easy way I can convert this to an Object[,]? UPDATE: The fact is I like to use Lists because I can easily add a new item. Is there a way I can declare my List<> object t...

linear simulation of multidimensional array

I know how to simulate a 2d array in a linear array using [x + y * width] as a linear index. I can extend this to 3d arrays: [x + y * width + z * width * height]. Is there a general formula for N-dimensional array? I'm looking for a language-agnostic answer. ...

Copy array of objects to array of different type

Previously, I ran into a problem trying to share a type definition between my ASMX webservice and my .aspx page (webclient) http://stackoverflow.com/questions/667619/confused-on-c-array-of-objects-and-implicit-type-conversion As I understand the advice, the "problem" this creates can be solved by copying the array of objects created in...