Search Results

Search found 15273 results on 611 pages for 'subtle array'.

Page 17/611 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • How to declare a 2D array of 2D array pointers and access them?

    - by vikramtheone
    Hi Guys, How can I declare an 2D array of 2D Pointers? And later access the individual array elements of the 2D arrays. Is my approach correct? void alloc_2D(int ***memory, unsigned int rows, unsigned int cols); int main() { int i, j; int **ptr; int **array[10][10]; for(i=0;i<10;i++) { for(j=0;j<10;j++) { alloc_2D(&ptr, 10, 10); array[i][j] = ptr; } } //After I do this, how can I access the 10 individual 2D arrays? return 0; } void alloc_2D(int ***memory, unsigned int rows, unsigned int cols) { int **ptr; *memory = NULL; ptr = malloc(rows * sizeof(int*)); if(ptr == NULL) { printf("\nERROR: Memory allocation failed!"); } else { int i; for(i = 0; i< rows; i++) { ptr[i] = malloc(cols * sizeof(float)); if(ptr[i]==NULL) { printf("\nERROR: Memory allocation failed!"); } } } *memory = ptr; }

    Read the article

  • Integer array or struct array - which is better?

    - by MusiGenesis
    In my app, I'm storing Bitmap data in a two-dimensional integer array (int[,]). To access the R, G and B values I use something like this: // read: int i = _data[x, y]; byte B = (byte)(i >> 0); byte G = (byte)(i >> 8); byte R = (byte)(i >> 16); // write: _data[x, y] = BitConverter.ToInt32(new byte[] { B, G, R, 0 }, 0); I'm using integer arrays instead of an actual System.Drawing.Bitmap because my app runs on Windows Mobile devices where the memory available for creating bitmaps is severely limited. I'm wondering, though, if it would make more sense to declare a structure like this: public struct RGB { public byte R; public byte G; public byte B; } ... and then use an array of RGB instead of an array of int. This way I could easily read and write the separate R, G and B values without having to do bit-shifting and BitConverter-ing. I vaguely remember something from days of yore about byte variables being block-aligned on 32-bit systems, so that a byte actually takes up 4 bytes of memory instead of just 1 (but maybe this was just a Visual Basic thing). Would using an array of structs (like the RGB example` above) be faster than using an array of ints, and would it use 3/4 the memory or 3 times the memory of ints?

    Read the article

  • Best practice accessing an array set within a class

    - by user350599
    I have created a basic class for a customer. I haven't done this before and want to know the best way to access the data. Should I have a get() method for every field in the customer array or should I simply pass the customer array back and access with the page. i.e. Just return the array class Customer { protected $id; protected $customer; public function __construct($customer_id) { $this->id = $customer_id; $this->set_customer(); } protected function set_customer() { $query = mysql_query("SELECT * FROM customer WHERE id = '$this->id'"); $this->customer = mysql_fetch_row($query); } public function get_customer() { return $this->customer; } } versus create a method for each item in the array class Customer { protected $id; protected $customer; public function __construct($customer_id) { $this->id = $customer_id; $this->set_customer(); } protected function set_customer() { $query = mysql_query("SELECT * FROM customer WHERE id = '$this->id'"); $this->customer = mysql_fetch_row($query); } public function get_customer_name() { return $this->customer->customer_name; } ... ... } versus option 3 based on Tobias' feedback: (not sure if syntax is correct) class Customer { protected $id; protected $customer; public function __construct($customer_id) { $this->id = $customer_id; return $this->set_customer(); } protected function set_customer() { $query = mysql_query("SELECT * FROM customer WHERE id = '$this->id'"); return mysql_fetch_row($query); } }

    Read the article

  • Array indexOf implementation for Internet Explorer

    - by Daemon
    There are plenty of solutions on how to get the indexOf implementation into the Array prototype so that it works under Internet Explorer, however I've stumbled upon an issue that doesn't seem to be addressed anywhere I've looked so far. Using the pretty well agreed upon implementation at MDC, I have the following code that's being problematic now: // indexOf support for IE (from MDC) if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt /*, from*/) { var len = this.length >>> 0; var from = Number(arguments[1]) || 0; from = (from < 0) ? Math.ceil(from) : Math.floor(from); if (from < 0) from += len; for (; from < len; from++) { if (from in this && this[from] === elt) return from; } return -1; }; } var i = [1,2,3,4]; for (j in i) { alert(i[j]); } I am expecting to receive 4 alerts, each one containing one of the elements of the array. In Firefox and Chrome, that's exactly what I see, however in IE8 I get an additional alert containing the indexOf function code. What can be done to avoid this?

    Read the article

  • Classify data (cell array) based on years in MATLAB

    - by user2991243
    Suppose that we have this cell array of data : a={43 432 2006; 254 12 2008; 65 35 2000; 64 34 2000; 23 23 2006; 64 2 2010; 32 5 2006; 22 2 2010} Last column of this cell array is years. I want classify data(rows) based on years like this : a_2006 = {43 432 2006; 32 5 2006; 32 5 2006} a_2008 = {254 12 2008}; a_2000 = {65 35 2000; 64 34 2000} a_2010 = {64 2 2010; 22 2 2010} I have different years in column three in every cell array (this cell array is a sample) so I want an automatic method to determine the years and classify them to a_yearA , a_yearB etc. or other naming that I can distinguish years and call data years easily. How can I do this? Thanks.da

    Read the article

  • Is this 2D array initialization a bad idea?

    - by Brendan Long
    I have something I need a 2D array for, but for better cache performance, I'd rather have it actually be a normal array. Here's the idea I had but I don't know if it's a terrible idea: const int XWIDTH = 10, YWIDTH = 10; int main(){ int * tempInts = new int[XWIDTH * YWIDTH]; int ** ints = new int*[XWIDTH]; for(int i=0; i<XWIDTH; i++){ ints[i] = &tempInts[i*YWIDTH]; } // do things with ints delete[] ints[0]; delete[] ints; return 0; } So the idea is that instead of newing a bunch of arrays (and having them placed in different places in memory), I just point to an array I made all at once. The reason for the delete[] (int*) ints; is because I'm actually doing this in a class and it would save [trivial amounts of] memory to not save the original pointer. Just wondering if there's any reasons this is a horrible idea. Or if there's an easier/better way. The goal is to be able to access the array as ints[x][y] rather than ints[x*YWIDTH+y].

    Read the article

  • Array indexOf implentation for Internet Explorer

    - by Daemon
    There are plenty of solutions on how to get the indexOf implementation into the Array prototype so that it works under Internet Explorer, however I've stumbled upon an issue that doesn't seem to be addressed anywhere I've looked so far. Using the pretty well agreed upon implementation at MDC, I have the following code that's being problematic now: // indexOf support for IE (from MDC) if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt /*, from*/) { var len = this.length >>> 0; var from = Number(arguments[1]) || 0; from = (from < 0) ? Math.ceil(from) : Math.floor(from); if (from < 0) from += len; for (; from < len; from++) { if (from in this && this[from] === elt) return from; } return -1; }; } var i = [1,2,3,4]; for (j in i) { alert(i[j]); } I am expecting to receive 4 alerts, each one containing one of the elements of the array. In Firefox and Chrome, that's exactly what I see, however in IE8 I get an additional alert containing the indexOf function code. What can be done to avoid this?

    Read the article

  • Ruby method Array#<< not updating the array in hash

    - by Mladen Jablanovic
    Inspired by http://stackoverflow.com/questions/2552363/how-can-i-marshal-a-hash-with-arrays I wonder what's the reason that Array#<< won't work properly in the following code: h = Hash.new{Array.new} #=> {} h[0] #=> [] h[0] << 'a' #=> ["a"] h[0] #=> [] # why?! h[0] += ['a'] #=> ["a"] h[0] #=> ["a"] # as expected Does it have to do with the fact that << changes the array in-place, while Array#+ creates a new instance?

    Read the article

  • Problem with comparing value with array values

    - by Java starter
    This code is what I use now. But it does not work when I try to use an array to compare values. If anybody has any idea of why, please respond. <html> <head> <script type-'text/javascript'> function hovedFunksjon() { //alert("test av funksjon fungerte"); //alert(passordLager); window.open("index10.html","Window1","menubar=no,width=430,height=360,toolbar=no"); } function inArray(array, value) { for (var i = 0; i < array.length; i++) { if (array[i] == value) return true; } return false; } function spørOmPassord() { var passordLager = ["pass0","pass1","pass2"]; window.passordInput = prompt("password");//Ved å bruke "window." skaper man en global variabel //if (passordInput == passordLager[0] || passordLager[1] || passordLager[2]) if (inArray(passordLager,passorInput) ) { hovedFunksjon(); } else { alert("Feil passord"); //href="javascript:self.close()">close window } } function changeBackgroundColor() { //document.bgColor="#CC9900"; //document.bgColor="YELLOW" document.bgColor="BLACK" } </script> </head> <body> <script type-'text/javascript'> changeBackgroundColor(); </script> <div align="center"> <form> <input type = "button" value = "Logg inn" onclick="spørOmPassord()"> </form> </div> </body> </html>

    Read the article

  • comparing value with array value problem Javascript

    - by Java starter
    This code is what I use now, it dos not work when I trie to use an array to compate values. If anybody has any idea of why, please respond. <html> <head> <script type-'text/javascript'> function hovedFunksjon() { //alert("test av funksjon fungerte"); //alert(passordLager); window.open("index10.html","Window1","menubar=no,width=430,height=360,toolbar=no"); } function inArray(array, value) { for (var i = 0; i < array.length; i++) { if (array[i] == value) return true; } return false; } function spørOmPassord() { var passordLager = ["pass0","pass1","pass2"]; window.passordInput = prompt("password");//Ved å bruke "window." skaper man en global variabel //if (passordInput == passordLager[0] || passordLager[1] || passordLager[2]) if (inArray(passordLager,passorInput) ) { hovedFunksjon(); } else { alert("Feil passord"); //href="javascript:self.close()">close window } } function changeBackgroundColor() { //document.bgColor="#CC9900"; //document.bgColor="YELLOW" document.bgColor="BLACK" } </script> </head> <body> <script type-'text/javascript'> changeBackgroundColor(); </script> <div align="center"> <form> <input type = "button" value = "Logg inn" onclick="spørOmPassord()"> </form> </div> </body> </html>

    Read the article

  • VB 2008 - Index was outside the bounds of the array

    - by Jan
    Hey guys I'm having a problem while reading a config.cfg file of my program. I can read the 23. char of the file but I can't read the 24. char (last char in file). This is the code: Dim CFGReader2 As System.IO.StreamReader CFGReader2 = _ My.Computer.FileSystem.OpenTextFileReader(CurDir() & "\Config.cfg") Dim Server(2) As String Server(0) = CFGReader2.ReadToEnd.Chars(23)//This part works If Server(0) = 0 Then Server(1) = CFGReader2.ReadToEnd.Chars(24)//This part results in "Index was outside the bounds of the array". ElseIf Server(0) = 1 Then Server(2) = CFGReader2.ReadToEnd.Chars(24)//This part results in "Index was outside the bounds of the array". Server(1) = 10 + Server(2) ElseIf Server(0) = 2 Then Server(2) = CFGReader2.ReadToEnd.Chars(24)//This part results in "Index was outside the bounds of the array". Server(1) = 20 + Server(2) ElseIf Server(0) = 3 Then Server(2) = CFGReader2.ReadToEnd.Chars(24)//This part results in "Index was outside the bounds of the array". Server(1) = 30 + Server(2) End If And this is the file: Language = 2 Server = 11 Thanks for the answer! Frosty

    Read the article

  • Reference problem when returning an object from array in PHP

    - by avastreg
    I've a reference problem; the example should be more descriptive than me :P I have a class that has an array of objects and retrieve them through a key (string), like an associative array: class Collection { public $elements; function __construct() { $this->elements = array(); } public function get_element($key) { foreach($this->elements as $element) { if ($element->key == $key) { return $element; break; } } return null; } public function add_element ($element) { $this->elements[] = $element; } } Then i have an object (generic), with a key and some variables: class Element { public $key; public $another_var; public function __construct($key) { $this->key = $key; $this->another_var = "default"; } } Now, i create my collection: $collection = new Collection(); $collection->add_element(new Element("test1")); $collection->add_element(new Element("test2")); And then i try to change variable of an element contained in my "array": $element = $collection->get_element("test1"); $element->another_var = "random_string"; echo $collection->get_element("test1")->another_var; Ok, the output is random_string so i know that my object is passed to $element in reference mode. But if i do, instead: $element = $collection-get_element("test1"); $element = null; //or $element = new GenericObject(); $element-another_var = "bla"; echo $collection-get_element("test1")-another_var; the output is default like if it lost the reference. So, what's wrong? I have got the references to the variables of the element and not to the element itself? Any ideas?

    Read the article

  • Question about array subscripting in C#

    - by Michael J
    Back in the old days of C, one could use array subscripting to address storage in very useful ways. For example, one could declare an array as such. This array represents an EEPROM image with 8 bit words. BYTE eepromImage[1024] = { ... }; And later refer to that array as if it were really multi-dimensional storage BYTE mpuImage[2][512] = eepromImage; I'm sure I have the syntax wrong, but I hope you get the idea. Anyway, this projected a two dimension image of what is really single dimensional storage. The two dimensional projection represents the EEPROM image when loaded into the memory of an MPU with 16 bit words. In C one could reference the storage multi-dimensionaly and change values and the changed values would show up in the real (single dimension) storage almost as if by magic. Is it possible to do this same thing using C#? Our current solution uses multiple arrays and event handlers to keep things synchronized. This kind of works but it is additional complexity that we would like to avoid if there is a better way.

    Read the article

  • How to loop through an array return from the Query of Mysql

    - by Jerry
    This might be easy for you guys but i could't get it. I have a php class that query the database and return the query result. I assign the result to an array and wants to use it on my main.php script. I have tried to use echo $var[0] or echo $var[1] but the output are 'array' instead of my value. Anyone can help me about this issue? Thanks a lot! My php class <?php class teamQuery { function teamQuery(){ } function getAllTeam(){ $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS); if (!$connection) { die("Database connection failed: " . mysql_error()); } $db_select = mysql_select_db(DB_NAME,$connection); if (!$db_select) { die("Database selection failed: " . mysql_error()); } $teamQuery=mysql_query("SELECT * FROM team", $connection); if (!$teamQuery){ die("database has errors: ".mysql_error()); } $ret = array(); while($row=mysql_fetch_array($teamQuery)){ $ret[]=$row; } mysql_free_result($teamQuery); return $ret; } } ?> My php on the main.php $getTeam=new teamQuery(); $team=$getTeam->getAllTeam(); //echo $team[0] or team[1] output 'array' string! // while($team){ // do something } can't work either // How to loop through the values?? Thanks!

    Read the article

  • PHP array minor problem

    - by Sennheiser
    I'm really not sure how to explain this. It's so simple I can't fathom why it's not working. I have a loop. It puts a bunch of strings into an array. If I fill a single variable with any given string, it will output it perfectly. But filling an array with the strings will make it give me the dreaded: Array Array Array Array Array Array Array Array Note: my strings are not all 'Array'. The way I loop is: while(...) { $arr[] = $resultFromLoop; } Here is my var_dump. array(1) { ["tagName"]=> string(5) "magic" } array(1) { ["tagName"]=> string(4) "nunu" } array(1) { ["tagName"]=> string(5) "books" } array(1) { ["tagName"]=> string(0) "" } array(1) { ["tagName"]=> string(3) "zzz" } array(1) { ["tagName"]=> string(4) "grey" } array(1) { ["tagName"]=> string(3) "new" } array(1) { ["tagName"]=> string(6) "flight" }

    Read the article

  • PHP - Search array in array

    - by Anonymous2011
    I have tried googling for the past one hour straight now and tried many ways to search for an array, in an array. My objective is, to find a keyword in the URL, and the keywords are in a txt file. This is what i have so far - but doesn't work. $file = "keywords.txt"; $open = fopen($file,'r'); $data = fread($open,filesize($file)); $data = explode(" ",$data); $url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $url = parse_url($url); //parse the URL into an array foreach($data as $d) { if(strstr($d,$url)) { echo "yes"; } } This works WITHOUT the text file, or array - but that's not what i want. I'd appreciate it if anyone can assist me.

    Read the article

  • Express one dimension of 2d array as new array

    - by user208080
    I have a 2d array a[3,3]. How can I express one dimension as a new array and pass it to some function? int[,] a = new int[3,3]; a[0,0] = 1; ... string b = concatenate(a[0]); // where concatenate is a function // take a one dimension array as param Also, can I create a 65000x65000 array with C#? I got some "out of memory" error.

    Read the article

  • php values of one array to key of another array

    - by mark
    I have 2 arrays $arr1 = Array ( [0] => 12 [1] => 4 [2] => 8 [3] => xx [4] => 1 [5] => 1year [6] => 7 ) $arr2 = Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 ) I want to create a new array with the values of a2 as keys in $arr1. My resultant array should be like this $arr3 = Array ( [1] => 12 [2] => 4 [3] => 8 [4] => xx [5] => 1 [6] => 1year [7] => 7 )

    Read the article

  • jquery to create array from form data

    - by AndrewStevens
    I've been wrestling with this problem for a couple hours now. Essentially, what I need to do is take the following or similar HTML: <div id="excpdivs"> <div class="excpdiv" id="excpdiv0"> Date: <input name="excp[0][date]"> Open: <input name="excp[0][open]"> Close: <input name="excp[0][close]"> </div> <div class="excpdiv" id="expdiv1"> Date: <input name="excp[1][date]"> Open: <input name="excp[1][open]"> Close: <input name="excp[1][close]"> </div> and get an array similar to the following to a php script: Array ( [0] => Array ( [date] => 2012-09-15 [open] => 3:00 [close] => 5:00 ) [1] => Array ( [date] => 2012-09-16 [open] => 2:00 [close] => 5:00 ) ) My main problem is getting the values from the input elements. My latest attempt is the following: var results = []; $(".excpdiv").each(function(){ var item = {}; var inpts = $(this).find("input"); item.date = $(inpts.get(0)).val(); item.open = $(inpts.get(1)).val(); item.close = $(inpts.get(2)).val(); results.push(item); }); Am I on the right track or am I hopelessly lost?

    Read the article

  • Fastest way to read/store lots of multidimensional data? (Java)

    - by RemiX
    I have three questions about three nested loops: for (int x=0; x<400; x++) { for (int y=0; y<300; y++) { for (int z=0; z<400; z++) { // compute and store value } } } And I need to store all computed values. My standard approach would be to use a 3D-array: values[x][y][z] = 1; // test value but this turns out to be slow: it takes 192 ms to complete this loop, where a single int-assignment int value = 1; // test value takes only 66 ms. 1) Why is an array so relatively slow? 2) And why does it get even slower when I put this in the inner loop: values[z][y][x] = 1; // (notice x and z switched) This takes more than 4 seconds! 3) Most importantly: Can I use a data structure that is as quick as the assignment of a single integer, but can store as much data as the 3D-array?

    Read the article

  • rearrange Array according to values order of another Array

    - by Exception
    I have two arrays like below var arr = ["x", "y", "z", "a", "b", "c"]; var tgtArr = [{val:"a"}, {val:"b"}]; It does not need to be as lengthy as Array `arr` This is what I have tried var dest = new Array(arr.length); for(var i = 0; i < arr.length; i++){ for(var k = 0; k < tgtArr.length; k++){ dest[i] = dest[i] || []; if(tgtArr[k].val == arr[i]){ dest[i] = arr[i]; } } } console.log(dest); My Expected output is (for above tgtArr value) [{}, {}, {}, {val:"a"}, {val:"b"}, {}]; if tgtArr is empty Array [{},{},{},{},{},{}] Here is the fiddle. Any alternative for this, it seems not a good way to me as I am iterating through the entire array everytime.

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >