Search Results

Search found 15007 results on 601 pages for 'array'.

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

  • why does array initialization in function other than main is temporary? [on hold]

    - by shafeeq
    This is the code in which i initialize array "turn[20]" in main as well as in function "checkCollisionOrFood()",the four values turn[0],turn[1],turn[2],turn[3] are initialized to zero in main function,rest are being intialized in "checkCollisionOrFood()".This is where fault starts.when i initialize turn[4]=0 in "checkCollisionOrFood()" and then access it anywhere,it remains 0 in any function,but! when i initialize next turn[] i.e turn[5],the value of turn[4] gets depleted .i.e turn[4] have garbage value.turn[20] is global variable,its index"head" is also global.I'm stuck.Plz help me get out of it.Ishall be highly obliged for this act of kindness.This is my excerpt of code unsigned short checkCollisionOrFood(){ head=(head+1)%20; if(turn[head-1]==0){ turn[head]=0; /this is where turn[] is iniliazized and if i access turn[head] here i.e just after iniliazition then it gives correct value but if i access its previous value means turn[head-1]then it gives garbage value/ rowHead=(rowHead+1)%8; if(!(address[colHead]&(1<<rowHead)))return 1; else if((address[colHead]&(1<<rowHead))&& (!((colHead==foody)&&(rowHead==foodx))))gameOver(); else return 0; } if(turn[head-1]==1){ turn[head]=1; colHead=(colHead+1)%8; if(!(address[colHead]&(1<<rowHead)))return 1; else if((address[colHead]&(1<<rowHead))&& (!((colHead==foody)&&(rowHead==foodx))))gameOver(); else return 0; } } void main(void) { turn[0]=0;turn[1]=0;turn[2]=0;turn[3]=0; /these values of turn[] are not changed irrespective of where they are accessed./ while (1) { if(checkCollisionOrFood()) { PORTB=(address[colHead] |=1<<rowHead); turnOffTail(); blink(); } else { PORTB=address[colHead]; createFood(); blink(); } } } Plz help me.

    Read the article

  • PHP intersection between array and object

    - by nickf
    I have an object, let's say it's like this: class Foo { var $b, $a, $r; function __construct($B, $A, $R) { $this->b = $B; $this->a = $A; $this->r = $R; } } $f = new Foo(1, 2, 3); I want to get an arbitrary slice of this object's properties as an array. $desiredProperties = array('b', 'r'); $output = magicHere($foo, $desiredProperties); print_r($output); // array( // "b" => 1, // "r" => 3 // )

    Read the article

  • Objective-C initial values of created C-array

    - by kpower
    I create an array, similar to classic C (not NSArray or one of it's children) - something like BOOL i[5];. And I want to make all its values to be equal to NO. First of all, I didn't found any information about initial values of such arrays (I know that in classic C they will be undefined, but don't know exactly about Objective-C. I found info about classes and its inner data [after allocation, without initialization], but not about simple data types). And the second, if I should set array values manually - should I use memset(...); or something different? To prevent possible questions... I want to use this construction as array of temporary boolean flags and don't think that it is proved to use something like NSArray here.

    Read the article

  • Optimizing for speed - 4 dimensional array lookup in C

    - by Tiago
    I have a fitness function that is scoring the values on an int array based on data that lies on a 4D array. The profiler says this function is using 80% of CPU time (it needs to be called several million times). I can't seem to optimize it further (if it's even possible). Here is the function: unsigned int lookup_array[26][26][26][26]; /* lookup_array is a global variable */ unsigned int get_i_score(unsigned int *input) { register unsigned int i, score = 0; for(i = len - 3; i--; ) score += lookup_array[input[i]][input[i + 1]][input[i + 2]][input[i + 3]]; return(score) } I've tried to flatten the array to a single dimension but there was no improvement in performance. This is running on an IA32 CPU. Any CPU specific optimizations are also helpful. Thanks

    Read the article

  • Array of structures CLI

    - by Nitroglycerin
    public value struct ListOfWindows { HWND hWindow; int winID; String^ capName; }; thats my structure now i have created an array of them: array<ListOfWindows ^> ^ MyArray = gcnew array<ListOfWindows ^>(5); now to test if that works i made a simple function: void AddStruct( ) { HWND temp = ::FindWindow( NULL, "Test" ); if( temp == NULL ) return; MyArray[0]->hWindow = temp; // debug time error.. return; } ERROR: An unhandled exception of type 'System.NullReferenceException' occurred in Window.exe Additional information: Object reference not set to an instance of an object. dont know what to do.. kinda new to CLI so if you can help please do.. Thanks.

    Read the article

  • Passing big multi-dimensional array to function in C

    - by kirbuchi
    Hi, I'm having trouble passing a big array to a function in C. I declare: int image[height][width][3]={}; where height and width can be as big as 1500. And when I call: foo((void *)image,height,width); which is declared as follows: int *foo(const int *inputImage, int h, int w); I get segmentation fault error. What's strange is that if my values are: height=1200; width=290; theres no problem, but when they're: height=1200; width=291; i get the mentioned error. At 4 bytes per integer with both height and width of 1500 (absolute worst case) the array size would be of 27MB which imo isn't that big and shouldn't really matter because I'm only passing a pointer to the first element of the array. Any advice?

    Read the article

  • Javascript array of href's

    - by Jason
    Hi, I am trying to create an array with different href's to then attach to 5 separate elements. This is my code: var link = new Array('link1', 'link2', 'link3', 'link4', 'link5'); $(document.createElement("li")) .attr('class',options.numericId + (i+1)) .html('<a rel='+ i +' href=\"page.php# + 'link'\">'+ '</a>') .appendTo($("."+ options.numericId)) As you can see I am trying to append these items from the array to the end of my page so each link will take the user to a different section of the page. But i have not been able to do this. Is there a way to to create elements with different links? I am new to javascript so I am sorry if this doesn't make a whole lot of sense. If anyone is confused by what i am asking here I can try to clarify if I get some feedback. Any solutions would be greatly appreciated. Thanks, jason

    Read the article

  • Change values in first key from 0 to count(array) - 1

    - by sologhost
    Ok, I have an array like so: $myArray[32]['value'] = 'value1'; $myArray[32]['type'] = 'type1'; $myArray[33]['value'] = 'value2'; $myArray[33]['type'] = 'type2'; $myArray[35]['value'] = 'value3'; $myArray[42]['value'] = 'value4'; $myArray[42]['type'] = 'type4'; Ok, looking for a quick way to change all numbers in the first key 32, 33, 35, and 42 into 0, 1, 2, and 3 instead. But I need to preserve the 2nd key and all of the values. The array is already ordered correctly, since I ordered it using a ksort, but now I need to reset the array from 0 - count($myArray) - 1 and keep the 2nd key intact and its value as well. Can someone please help me?

    Read the article

  • Array.BinarySearch does not find item using IComparable

    - by Sir Psycho
    If a binary search requires an array to be sorted before hand, why does the following code work? string[] strings = new[] { "z", "a", "y", "e", "v", "u" }; int pos = Array.BinarySearch(strings, "Y", StringComparer.OrdinalIgnoreCase); Console.WriteLine(pos); And why does this code result return -1? public class Person : IComparable<Person> { public string Name { get; set; } public int Age { get; set; } public int CompareTo(Person other) { return this.Age.CompareTo(other.Age) + this.Name.CompareTo(other.Name); } } var people = new[] { new Person { Age=5,Name="Tom"}, new Person { Age=1,Name="Tom"}, new Person { Age=2,Name="Tom"}, new Person { Age=1,Name="John"}, new Person { Age=1,Name="Bob"}, }; var s = new Person { Age = 1, Name = "Tom" }; // returns -1 Console.WriteLine( Array.BinarySearch(people, s) );

    Read the article

  • Formula needed: Sort Array

    - by aw
    I have the following array: a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] I use it for some visual stuff like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Now I want to sort the array like this: 1 3 6 10 2 5 9 13 4 8 12 15 7 11 14 16 //So the original array should look like this: a = [1,5,2,9,6,3,13,10,7,4,14,11,8,15,12,16] Yeah, now I'm looking for a smart formula to do that ticker = 0; originalArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] newArray = []; while(ticker < originalArray.length) { //do the magic here ticker++; }

    Read the article

  • Copying non null-terminated unsigned char array to std::string

    - by karlphillip
    If the array was null-terminated this would be pretty straight forward: unsigned char u_array[4] = { 'a', 's', 'd', '\0' }; std::string str = reinterpret_cast<char*>(u_array); std::cout << "-> " << str << std::endl; However, I wonder what is the most appropriate way to copy a non null-terminated unsigned char array, like the following: unsigned char u_array[4] = { 'a', 's', 'd', 'f' }; into a std::string. Is there any way to do it without iterating over the unsigned char array? Thank you all.

    Read the article

  • Newtonsoft.json throwing error: Array was not a one-dimensional array.

    - by SIA
    Hi everybody, I am getting an error when trying to serialize an object products. Product product = new Product(); product.Name = "Apple"; product.Expiry = new DateTime(2008, 12, 28); product.Price = 3.99M; product.Sizes = new string[3,2] { {"Small","40"}, {"Medium","44"}, {"Large","50"} }; string json = JsonConvert.SerializeObject(product);//this line is throwing an error Array was not a one-dimensional array Is there any way to serialize a two dimensional array with Newtonsoft.json Thanks in Advance. SIA

    Read the article

  • php push 2d array into mysql

    - by john
    Hay All, I cant seem to get my head around this dispite the number to examples i read. Basically I have a 2d array and want to insert it into MySQL. The array contains a few strings. I cant get the following to work... $value = addslashes(serialize($temp3));//temp3 is my 2d array, do i need to use keys? (i am not at the moment) $query = "INSERT INTO table sip (id,keyword,data,flags) VALUES(\"$value\")"; mysql_query($query) or die("Failed Query"); Thanks Guys,

    Read the article

  • PL/SQL bulk collect into associative array with sparse key

    - by Dan
    I want to execute a SQL query inside PL/SQL and populate the results into an associative array, where one of the columns in the SQL becomes the key in the associative array. For example, say I have a table Person with columns PERSON_ID INTEGER PRIMARY KEY PERSON_NAME VARCHAR2(50) ...and values like: PERSON_ID | PERSON_NAME ------------------------ 6 | Alice 15 | Bob 1234 | Carol I want to bulk collect this table into a TABLE OF VARCHAR2(50) INDEX BY INTEGER such that the key 6 in this associative array has the value Alice and so on. Can this be done in PL/SQL? If so, how?

    Read the article

  • How to create an array from database?

    - by Sofyan
    Hi, Please help me to create an array from a field of my DB. That field has records separated by comma. Below is the illustration: ID | article_title_fld | article_tags_fld | ---------------------------------------------------------------------- 1 | Learn PHP | PHP, coding, scripting | 3 | Javascript Tutorial | Javascript, scripting, tutorial | 4 | Styling with CSS | CSS, tutorial, web design | I want to collect all records in the article_tags_fld then put it into 1 array. Perhaps I named it $array1, and the print out as below: Array ( [0] => PHP [1] => coding [2] => scripting [3] => Javascript [4] => scripting [5] => tutorial [6] => CSS [7] => tutorial [8] => web design )

    Read the article

  • Getting data from a ListView into an array

    - by Joe
    I have a ListView control on my form set up like this in details mode: What I would like to do, is get all the values of the data cells when the user presses the Delete booking button. So using the above example, my array would be filled with this data: values(0) = "asd" values(1) = "BS1" values(2) = "asd" values(3) = "21/04/2010" values(4) = "2" This is my code so far: Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim items As ListView.SelectedListViewItemCollection = _ Me.ManageList.SelectedItems Dim item As ListViewItem Dim values(0 To 4) As String Dim i As Integer = 0 For Each item In items values(i) = item.SubItems(i).Text i = i + 1 Next End Sub But only values(0) gets filled with the first data cell of the selection (in this case "asd") and the rest of the array entries are blank. I have confirmed this with a breakpoint and checked the array entries myself. I'm REALLY lost on this, and have been trying for about an hour now. Any help would be appreciated, thanks :) Also please note that there can only be one row selection at once. Thanks.

    Read the article

  • how to replace multi string with a array node in js

    - by Rueta
    hi everyone! i here a Work and i don't know how to do it. i have a string here: <div class="demotext"> <p>this is demo string i demo want to demo use</p> </div> i create the array variable for demo: var demoarray = new array('a','b','c'); now i want replace 'demo' in string by array node, follow 'demo' one change to 'a' , 'demo' two change to 'b'....

    Read the article

  • Perl, dereference array of references

    - by Mike
    In the following Perl code, I would expect to be referencing an array reference inside an array #!/usr/bin/perl use strict; use warnings; my @a=([1,2],[3,4]); my @b = @$a[0]; print $b[0]; However it doesn't seem to work. I would expect it to output 1. @a is an array of references @b is $a[1] dereferenced (I think) So what's the problem?

    Read the article

  • Question regarding two dimensional array

    - by Sherwood Hu
    I have some problems using two dimensional array in the code and need some help. static const int PATTERNS[20][4]; static void init_PATTERN() { // problem #1 int (&patterns)[20][4] = const_cast<int[20][4]>(PATTERNS); ... } extern void UsePattern(int a, const int** patterns, int patterns_size); // problem #2 UsePattern(10, PATTERNS, sizeof(PATTERNS)/sizeof(PATTERNS[0])); in the first statement, I need to cast the const off the two dimensional array PATTERNS. The reason for this is that the init function is called only once, and in the remaining code, PATTERNS is strictly read-only. In the second statement, I need to pass PATTERNS array to the int** argument. Direct passing resulted a compile error. Thanks!

    Read the article

  • Copy an array backwards? Array.Copy?

    - by daniel
    I have a List<T> that I want to be able to copy to an array backwards, meaning start from List.Count and copy maybe 5 items starting at the end of the list and working its way backwards. I could do this with a simple reverse for loop; however there is probably a faster/more efficient way of doing this so I thought I should ask. Can I use Array.Copy somehow? Originally I was using a Queue as that pops it off in the correct order I need, but I now need to pop off multiple items at once into an array and I thought a list would be faster.

    Read the article

  • How to create two dimensional array in jquery or js

    - by learner
    I need to create dynamic global two dimensional array in jquery or javascript My function is like this <script> var index = 0; var globalArray = new Array(); function createArray(){ var loop = globalArray[index].length; var name = $.("#uname").val(); if(loop == 0){ globalArray[index][0] = uname; }else{ globalArray[index][loop++] = uname; } } </script> <div><input type="text" id="uname"> <input type='button' value='save' onclick='createArray();'> </div> On click of that button I am getting this error "globalArray[index] is undefined" How can I create one global array using jquery or javascript like this. I dont want any hidden field and all. Please help me. Thanks

    Read the article

  • php multidimensional array problem

    - by ntan
    Hi to all, i am trying to setup a multidimensional array but my problem is that i can not get the right order from incoming data. Explain $x[1][11]=11; $x[1]=1; var_dump($x); In the above code i get only x[1]. To right would be $x[1]=1; $x[1][11]=11; var_dump($x); But in my case i can dot ensure that x[1] will come first, and x[1][11] will come after. Is there any way that i can use the first example and get right the array. Keep in mind that the array depth is large. Thats

    Read the article

  • Deleting Part of An Array in Java to Free Memory on Heap

    - by kate
    I am implementing a dynamic programming algorithm for the knapsack problem in Java. I declare the array and then initialize its size to be [number of objects][capacity of knapsack]. When my number of objects or my capacity gets too large, I get a memory error because I run out of space on the heap. My questions is: If I delete rows from my double array as I go along, will Java free the memory as I delete? Or does Java reserve that memory space for the size of the array I originally created? If it's the latter, is there a way to manually free the memory in Java? Thanks for your Help!

    Read the article

  • Sorting Multidimensional Array with Javascript: Integers

    - by tkm256
    I have a 2D array called "results." Each "row" array in results contains both string and integer values. I'm using this script to sort the array by any "column" on an onclick event: function sort_array(results, column, direction) { var sorted_results = results.sort(value); function value(a,b) { a = a[column]; b = b[column]; return a == b ? 0 : (a < b ? -1*direction : 1*direction) } } This works fine for the columns with strings. But it treats the columns of integers like strings instead of numbers. For example, the values 15, 1000, 200, 97 would be sorted 1000, 15, 200, 97 if "ascending" or 97, 200, 15, 1000 "descending." I've double-checked the typeof the integer values, and the script knows they're numbers. How can I get it to treat them as such?

    Read the article

  • Make jquery array out of div

    - by Industrial
    Hi everyone, Each div with the class "row" is added upon request from the user, to be able to add multiple items at once. So now is the question how I'll collect all the forms in to an array that PHP can read (like JSON for instance). I'll guess that there's already some easy and effective way of doing this? <div class="container"> <div class="row"> <input type="text" name="value1" id="textfield" /> <input type="text" name="value2" id="textfield" /> <input type="text" name="value3" id="textfield" /> </div> </div> Here's what I would like to achieve out of the shown example: array( array ('value1' => '', 'value2' => '', 'value3' => '') ); Thanks!

    Read the article

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