arrays

Warning while passing 2d array

I have the following function void initBoard(int * board[BOARD_ROWS][BOARD_COLS]){ int z = 0; for( z = 0; z<10; z+=1){ int l; for( l = 0; l<10; l+=1){ board[z][l] = 0; } } } and from main i call it like int plBoard[10][10]; initBoard(&pcBoard); when compiling it works but i get a warning saying: war...

2d arrays of ints in objective-c

I am working with C style 2d arrays of integers. This is fine in my main class file, and I can pass my arrays by reference to other classes. I have run into issues when I try to retrieve a pointer to the arrays and work with that. My question is: rather than using C style 2d arrays, is there a better way to do it? maybe a Cocoa class I...

K&R: array of character pointers

On pg. 109 of K&R, we see: void writelines(char *lineptr[], int nlines) { while (nlines -- > 0) printf("%s\n", *lineptr++); } I'm confused about what *lineptr++ does exactly. From my understanding, printf requires a char pointer, so we provide that with *lineptr. Then we increment lineptr up to the next char pointer in the array? Is...

PHP: Sort an array by the length of its values?

I made an anagram machine and I have an array of positive matches. The trouble is they are all in a different order, I want to be able to sort the array so the longest array values appear first. Anybody have any ideas on how to do this? ...

array of stacks

Is it possible to create an array of stacks without having to cast the stacks as they come out? Eclipse gives me a warning about not being able to make a generic array of Stack when I do something like this: Stack<Card>[] cards = new Stack<Card>[52]; ...

Why should I use malloc() when "char bigchar[ 1 << 31 - 1 ];" works just fine?

What's the advantage of using malloc (besides the NULL return on failure) over static arrays? The following program will eat up all my ram and start filling swap only if the loops are uncommented. It does not crash. ... #include unsigned int bigint[ 1 << 29 - 1 ]; unsigned char bigchar[ 1 << 31 - 1 ]; int main (int argc, char **argv)...

C# StructLayout/FieldOffset and indexing in arrays

I'm having a bit of a problem using FieldOffset correctly with arrays. The code below is an example where it doesn't work correctly for me: [StructLayout(LayoutKind.Explicit)] public struct IndexStruct { [FieldOffset(0)] public byte[] data; [FieldOffset(0)] public short[] idx16; [FieldOffset(0)] public int[] idx32; } If I for ...

Easiest way to find duplicate values in a javascript array

I need to check a javascript array to see if there are any duplicate values. What's the easiest way to do this? I just need to find what the duplicated values are - I don't actually need their indexes or how many times they are duplicated. I know I can loop through the array and check all the other values for a match, but it seems like ...

Nested sets, php array and transformation

Hi, I need to transform my nested sets structure (mysql) into json for this spacetree 1) http://blog.thejit.org/wp-content/jit-1.0a/examples/spacetree.html I found this function to create an array from nested sets: 2) http://semlabs.co.uk/journal/converting-nested-set-model-data-in-to-multi-dimensional-arrays-in-php I can also convert...

Defining Array in template.php Drupal

I have a drupal function that contains an array. I want to redefine one of the variables in that array. Do I just copy paste that entire function into template.php and change the variable to what I want it to be? Thanks. ...

PHP foreach loop through multidimensional array

I have an array: $arr_nav = array( array( "id" => "apple", "url" => "apple.html", "name" => "My Apple" ), array( "id" => "orange", "url" => "orange/oranges.html", "name" => "View All Oranges", ), array( "id" => "pear", "url" => "pear.html", "name" => "A Pear" ) );...

accessing an item in array in PHP

In PHP I would like to get the text value of the customer name tag. I write this code but this does not work. Would you please help me with this? Thank you $customerName = $dom->get_elements_by_tagname("item"); $customernameValue = customerName[0]-> first_child()->node_value (); ...

initializng a C array with repetitive data

I would like to initialize an array of structs, with the same element repetitively, ie struct st ar[] = { {1,2}, {1,2}, {1,2} }; However I do NOT want to run any code for that, I wish that the layout of the memory upon program's execution would be like so, without any CPU instructions involved (it would increase boot time on very slow...

How to Initialize a Multidimensional Char Array in C?

I'm trying to convert some code from C# to C so that it can be burnt onto a microcontroller. Could someone please tell me how I would convert a two dimensional string array in C# into something in C? My C# code looks like this: string[,] DirectionPosition = {{"00", "10", "", "01", ""}, {"01", "...

Can i return an array of "number, number" in json format?

Hi folks, i have a list of lat/long objects on my server. eg. public class LatitudeLongitude { public float Latitude; public float Longitude; } simple. now, can i return a collection of these, in json format .. BUT ... i do not want to list the key, just the values. This means the normal result would be something like ... ...

How can I return an array?

Is there any way to return an array from a function? More specifically, I've created this function: char bin[8]; for(int i = 7; i >= 0; i--) { int ascii='a'; if(2^i-ascii >= 0) { bin[i]='1'; ascii=2^i-ascii; } else { bin[i]='0'; } } and I need a way to return bin[]. ...

Array of linked lists in C++

Some code for context: class WordTable { public: WordTable(); ~WordTable(); List* GetListByAlphaKey(char key); void AddListByKey(char key); bool ListExists(char key); bool WordExists(string word); void AddWord(string word); void IncrementWordOccurances(string word); void Print(); private: List *_listArray[33]; int...

In VBA, how to return an array / or write to cells using a function?

Using this very simple function: Function WriteArray() as Variant Dim array(0 To 2) array(0) = "A" array(1) = "B" array(2) = "C" WriteArray = array End Function I was expecting to see in result the whole array in my Excel spreadsheet, but that's not the case: I get only the first string. I know there is trick to show the whole ar...

Delphi Array Alignment set to 4, 8, or 16 byte boundaries?

I would like to use the FFTW C library from Delphi 2009 and according to this documentation; http://www.fftw.org/install/fftw_usage_from_delphi.txt to increase the performance inside the FFTW library (such that it can use SIMD extensions) arrays passed in of either Single (float) or Double (double) need to be aligned either at 4 or 8 b...

Easily access an array based on its dimensions

Lets say I have an array which has n dimensions. Now in order to access a slot you typically use: array [1][0] What if the number of dimensions are not known at compile-time, is there an easy access like: slot = "1,0" array [slot] // accessing 1,0 Which means I can also easily navigate back and forth slot += ",2" array [slo...