Search Results

Search found 17397 results on 696 pages for '2d array'.

Page 11/696 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • daynamic 2d array in c++ and memory leaks

    - by SepiDev
    Hi guys, i wrote this code, it runs ok, but when i check it under Valgrind it catches 2 problems, since i can not interpret valgrind's messages i will appreciate if anyone explain me more and tell me where is the problem!!! here is the code: #include <iostream> #define width 70000 #define height 10000 using namespace std; int main(void) { int** pint; pint = new int*[height]; for(int i = 0; i < height; i++) pint[i] = new int[width]; for(int i = 0; i < height; i++){ delete[] pint[i]; pint[i] = NULL; } delete[] pint; pint = NULL; return 1; }

    Read the article

  • C++ 2d Array Class Function Call Help

    - by johnny-conrad
    I hope this question takes a simple fix, and I am just missing something very small. I am in my second semester of C++ in college, and we are just getting into OOP. This is my first OOP program, and it is causing me a little problem. Here are the errors I am getting: Member function must be called or its address taken in function displayGrid(int,Cell ( *)[20]) Member function must be called or its address taken in function Turn(int,int,Cell ( *)[20]) Member function must be called or its address taken in function Turn(int,int,Cell ( *)[20]) Warning: Parameter 'grid' is never used in function displayGrid(int,Cell ( *)[20]) Here is all of my code. I am aware It is much more code than necessary, sorry if it makes it more difficult. I was worried that I might accidentally delete something. const int MAX=20; //Struct Cell holds player and their symbol. class Cell { private: int Player; char Symbol; public: Cell(void); void setPlayer(int); void setSymbol(char); int getPlayer(void); char getSymbol(void); }; Cell::Cell(void) { Symbol ='-'; } void Cell::setPlayer(int player_num) { Player = player_num; } void Cell::setSymbol(char rps) { Symbol = rps; } int Cell::getPlayer(void) { return Player; } char Cell::getSymbol(void) { return Symbol; } void Turn(int, int, Cell[MAX][MAX]); void displayGrid(int, Cell[MAX][MAX]); void main(void) { int size; cout << "How big would you like the grid to be: "; cin >> size; //Checks to see valid grid size while(size>MAX || size<3) { cout << "Grid size must between 20 and 3." << endl; cout << "Please re-enter the grid size: "; cin >> size; } int cnt=1; int full; Cell grid[MAX][MAX]; //I use full to detect when the game is over by squaring size. full = size*size; cout << "Starting a new game." << endl; //Exits loop when cnt reaches full. while(cnt<full+1) { displayGrid(size, grid); //calls function to display grid if(cnt%2==0) //if cnt is even then it's 2nd players turn cout << "Player 2's turn." << endl; else cout << "Player 1's turn" << endl; Turn(size, cnt, grid); //calls Turn do each players turn cnt++; } cout << endl; cout << "Board is full... Game Over" << endl; } void displayGrid(int size, Cell grid[MAX][MAX]) { cout << endl; cout << " "; for(int x=1; x<size+1; x++) // prints first row cout << setw(3) << x; // of numbers. cout << endl; //Nested-For prints the grid. for(int i=1; i<size+1; i++) { cout << setw(2) << i; for(int c=1; c<size+1; c++) { cout << setw(3) << grid[i][c].getSymbol; } cout << endl; } cout << endl; } void Turn(int size, int cnt, Cell grid[MAX][MAX]) { char temp; char choice; int row=0; int column=0; cout << "Enter the Row: "; cin >> row; cout << "Enter the Column: "; cin >> column; //puts what is in the current cell in "temp" temp = grid[row][column].getSymbol; //Checks to see if temp is occupied or not while(temp!='-') { cout << "Cell space is Occupied..." << endl; cout << "Enter the Row: "; cin >> row; cout << "Enter the Column: "; cin >> column; temp = grid[row][column].getSymbol; //exits loop when finally correct } if(cnt%2==0) //if cnt is even then its player 2's turn { cout << "Enter your Symbol R, P, or S (Capitals): "; cin >> choice; grid[row][column].setPlayer(1); in >> choice; } //officially sets choice to grid cell grid[row][column].setSymbol(choice); } else //if cnt is odd then its player 1's turn { cout << "Enter your Symbol r, p, or s (Lower-Case): "; cin >> choice; grid[row][column].setPlayer(2); //checks for valid input by user1 while(choice!= 'r' && choice!='p' && choice!='s') { cout << "Invalid Symbol... Please Re-Enter: "; cin >> choice; } //officially sets choice to grid cell. grid[row][column].setSymbol(choice); } cout << endl; } Thanks alot for your help!

    Read the article

  • php transform array into multidim array

    - by fverswijver
    So I'm working on a website with Doctrine as ORM and I get the following array back as a result: Array ( [0] => Array ( [c_cat_id] => 1 [c_title] => Programas e projetos [p_menu] => PBA BR 163 [p_page_id] => 1 ) [1] => Array ( [c_cat_id] => 1 [c_title] => Programas e projetos [p_menu] => Outros projetos [p_page_id] => 3 ) ) Is it possible to transform this array (in PHP) to something like this: Array ( [0] => Array ( [c_cat_id] => 1 [c_title] => Programas e projetos [pages] => Array ([p_page_id] => 1 [p_menu] => PBA BR 163, [p_page_id] => 3 [p_menu] => Outros projetos)) Thanks for your help, always eager to learn new ways of doing things and that's why I love StackOverflow ;)

    Read the article

  • Sorting a 2D array in obj-c?

    - by Debashis
    I have a 2D array as follows: [[@"string value", @"string value", NSInteger], [@"string value", @"string value", NSInteger], [@"string value", @"string value", NSInteger]] How would I sort the second dimension of arrays by the NSInteger?

    Read the article

  • php foreach getting values from an array

    - by sea_1987
    I am having trouble accessing the values in an array, the array looks like this, Array ( [0] => Array ( [id] => 1661 [code] => 849651318 [job_status] => 4 [looking_for] => Lorem ipsum [keywords_education] => Derby University [sector_id_csv] => 10,21,9,22,26 [last_job_title_1] => Programmer [last_job_employer_1] => HBOS [city] => Bury [expected_salary_level] => LEVEL_2 [education_level] => COLLEGE [job_looking_for] => [is_contract] => Y [is_permanent] => N [is_temporary] => Y ) ) Array ( [0] => Array ( [id] => 402 [code] => 849650059 [job_status] => 3 [looking_for] => Lorem ipsum [keywords_education] => Paris College [sector_id_csv] => 27,22,19,21,12 [last_job_title_1] => Programmer [last_job_employer_1] => HSBC [city] => Bury [expected_salary_level] => LEVEL_2 [education_level] => COLLEGE [job_looking_for] => [is_contract] => N [is_permanent] => Y [is_temporary] => Y ) ) Array ( [0] => Array ( [id] => 1653 [code] => 849651310 [job_status] => 3 [looking_for] => Lorem ipsum [keywords_education] => Crewe University [sector_id_csv] => 27,15,19,21,24 [last_job_title_1] => Programmer [last_job_employer_1] => ICI [city] => Bury [expected_salary_level] => LEVEL_2 [education_level] => UNIVERSITY [job_looking_for] => [is_contract] => N [is_permanent] => Y [is_temporary] => Y ) ) I am trying to get the values out, I have tried doing the following, foreach ($result as $rslt) { echo $rslt->id; } I have also tried, foreach ($result as $rslt) { $rslt['id']; } But none of this works, I dont know why, can anyone help?

    Read the article

  • How to check if *number* is in a array

    - by Emil
    Pretty basic programming question, I know PHP have a function for it, but does the iPhone OS have one? I want to check if the current indexPath is a value in an array. PHP Example: <?php $indexPath = 3; $array = array("0", "1", "2", "3", "4"); if (in_array($indexPath, $array)) { // Do something } ?> Does anybody know how to do the same thing inthe iPhone OS?

    Read the article

  • return a php associative array to javascript array

    - by Eric Sim
    I am trying to return a php associative array to javascript array through ajaxRequest.responseText Here's what I do. First in php, I do this: $encoded = json_encode($thisarray); echo $encoded; If I echo $encoded, I get {"a":"apple,arrow","b":"boy,bank","c":"cat,camp"} Then in js script, thisarray = new Array(); thisarray = ajaxRequest.responseText; If I alert thisarray, I get {"a":"apple,arrow","b":"boy,bank","c":"cat,camp"} That's wrong since alerting an array should give error. But in this case, when I alert thisarray, I get the full array!! Needless to say, I can't call my value out of thisarray, since it is yet defined as an array. Anyone can tell me what am I missing here?

    Read the article

  • Copying 1-D array into 2 -D array

    - by Digvijay Yadav
    I have one two dimensional array and one single dimensional array. The two dimensional array is of NxM size. And the one dimensional array is of size N x M means it has N X M elements. Now I want to copy all the elements of the one dimensional array into the 2-D array. This is what I tried for(i = 0; i < M; i += 1) { for(j = 0; j < N; j += 1) { arr2d[i][j] = arr2d[(i*j +j)]; } } But not working Any suggestions???

    Read the article

  • Array sum of difference of first smallest k elment

    - by prateeak ojha
    Hi i come across this challenge on an online programing challange the task is so simple for ex WE have to variable N and K where N is where N is lenght of array and we have to find sum of duiffrence of K smallest element of array as Sample Input 10 4 1 2 3 4 10 20 30 40 100 200 Sample Output 10 Explanation #0 We have 10 as N size of array and K is 4 here the next N values are array's elments in order to find sum of diffrences we will takek smallest values from array which are 1,2,3,4 then will perform operation(sum of difference) as |1-2| + |1-3| + |1-4| + |2-3| + |2-4| + |3-4| = 10 I tried solving the problem and found a way through which i can solve the problem wit N^3 complexity but my solution is rejected i need a approach to solve the problem with n complexity i still can't figure out a way .. looked at some solution but coud'nt find the exact way to approach. if anybody have a better idea and would like to share it would be appreciable thanks in advance

    Read the article

  • Sorting an array in ascending order without losing the index Objective-C

    - by thary
    Hello all, I have an array for instance, Array { 3.0 at Index 0 2.0 at Index 1 3.5 at Index 2 1.0 at Index 4 } I would like to get sort it in ascending order without losing the index in the first place, like this, Array { 1.0 at Index 4 2.0 at Index 1 3.0 at Index 0 3.5 at Index 2 } When I sort the array using this, NSArray *sortedArray = [hArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; [knnRecog sortUsingDescriptors:[NSArray arrayWithObject:sortAsc]]; I lose the index. Does anyone know a way to preserve the index after sorting the array? Thanks

    Read the article

  • array_merge vs array_value for resetting array index

    - by Jamex
    I have 1 array that I want to re-index. I have found that both array_values and array_merge functions can do the job (and I don't need 2 arrays for the array_merge function to work). Which is faster for a very large array? I would benchmark this, but I don't know how and don't have the large array yet. Before re-index: Array ( [0] => AB [4] => EA [6] => FA [9] => DA [10] => AF ) After re-index: Array ( [0] => AB [1] => EA [2] => FA [3] => DA [4] => AF )

    Read the article

  • Traverse multi dimensional array recusively without using foreach

    - by ejaz
    I have an array like this and the code using foreach loop. $arr = array( array ( array( 'CAR_TIR', 'Tires', 100 ), array( 'CAR_OIL', 'Oil', 10 ), array( 'CAR_SPK', 'Spark Plugs', 4 ) ), array ( array( 'VAN_TIR', 'Tires', 120 ), array( 'VAN_OIL', 'Oil', 12 ), array( 'VAN_SPK', 'Spark Plugs', 5 ) ), array ( array( 'TRK_TIR', 'Tires', 150 ), array( 'TRK_OIL', 'Oil', 15 ), array( 'TRK_SPK', 'Spark Plugs', 6 ) ) ); function recarray($array) { foreach($array as $key=>$value) { if(is_array($value)) { RecArray($value); } else { echo "key = $key value = $value"; } } } recarray($arr); I have to traverse the array using recursion and without using foreach. I would appreciate it if any one can help me

    Read the article

  • Converting 3 dimension byte array to a single byte array [on hold]

    - by Andrew Simpson
    I have a 3 dimensional byte array. The 3-d array represents a jpeg image. Each channel/array represents part of the RGB spectrum. I am not interested in retaining black pixels. A black pixel is represented by this atypical arrangement: myarray[0,0,0] =0; myarray[0,0,1] =0; myarray[0,0,2] =0; So, I have flattened this 3d array out to a 1d array by doing this byte[] AFlatArray = new byte[width x height x 3] and then assigning values respective to the coordinate. But like I said I do not want black pixels. So this array has to only contain color pixels with the x,y coordinate. The result I want is to re-represent the image from the i dimension byte array that only contains non-black pixels. How do I do that? It looks like I have to store black pixels as well because of the xy coordinate system. I have tried writing to a binary file but the size of that file is greater than the jpeg file as the jpeg file is compressed. I am using c#.

    Read the article

  • Render angles of a 3D model into 2D images?

    - by Ricket
    Is there a tool out there that you can give a 3D model file, and it will output 2D renders of it from various angles? For example if you were making a 2D RPG but you want to make your character look nice, you might make the character in 3D and then just render the character from 8 or more angles into images which then are used by the 2D engine to give a pseudo-3D look. Does such a tool exist or will it need to be custom-written or done manually?

    Read the article

  • Is there a good book or articles to learn about 2D Game Design and Effects?

    - by user28015
    I am not looking for a read how to develop games and how to implement one. I am looking for a general about possible effects in 2D Games and about general design of modern 2D gaming. I have programmed several smaller games over the years and also read books like "Golden Rules of Game Programming" by Martin Bronwlo. So I know how to implement games. What I am looking for are 2 things: Finishing touches such as effects like explosions, particles etc. Not how to make them, but how to design them so it looks right and cool. How to make a 2D game feel "more right" so that users get a satisfying gaming experience. I played a lot of 2D games but I could use some more advice.

    Read the article

  • How do I remove the unity 2D option in lightdm (login sceen) in ubuntu 12.04?

    - by user113460
    Because I wish to view my full username at login, I want to remove the "Unity 2D" option at the login screen. Currently the last part of the username (after the 20th digit) is hidden behind the Ubuntu-icon which enables switching to Unity 2D. Another option would be to decrease the font-size of the username, is any of this possible? Btw this is not an issue in Ubuntu 12.10, where the username font-size is smaller, and Unity 2D unsupported!

    Read the article

  • Convert Array to Multidimensional Array

    - by Tim
    I like to convert a single array into a multidimensional array. This is what I get have web scraping a page, except it is not the end result that I am looking for. Change: Rooms: Array ( [0] => name [1] => value [2] => size [3] => &nbsp; [4] => name [5] => value [6] => size [7] => &nbsp; [8] => name [9] => value [10] => size [11] => &nbsp; [12] => name [13] => value [14] => size [15] => &nbsp; ) Into: Rooms: Array ( Room: Array ( [0] => name [1] => value [2] => size ), Room: Array ( [0] => name [1] => value [2] => size ), Room: Array ( [0] => name [1] => value [2] => size ) )

    Read the article

  • Matching array elements to get an array element at another index

    - by bccarlso
    I have a PHP array that I'm using to generate an HTML form. The PHP array is this: <?php $vdb = array ( array( "Alabama", 275), array( "Alaska", 197), array( "Arizona", 3322)); ?> The PHP to generate the HTML form is below. I need to have the value be the name of the state, because there is some AJAX I'm using to display which states a user has chosen. <?php echo "<table border='1'><thead><tr><th></th><th>State</th><th>Contacts</th><th>Email</th></tr></thead>"; for ($row = 0; $row < 42; $row++) { echo "<tr><td class='input_button'><input type='checkbox' name='vdb[]' value='".$vdb[$row][0]."' title='".$vdb[$row][1]."' /></td>"; echo "<td>".$vdb[$row][0]."</td>"; echo "<td>".$vdb[$row][1]."</td>"; } echo "</table>"; ?> What I'm trying to do is, on submission of the form, with the states the user selected, loop through the PHP array and total the numbers from the selected states. So if I checked Alabama and Alaska, I'd want to add 275 + 197. This is what I thought would have worked, but it's not: <?php $vendors = array(); if (isset($_POST["vdb"])) { $vendors = $_POST["vdb"]; } $ven_i = 0; $ven_j = 0; $ven_total = 0; foreach ($vendors as $value) { foreach ($vdb as $vdb_value) { if ($vendors[$ven_i] == $vdb[$ven_j][0]) { $ven_total += $vdb[$ven_j][1]; } $ven_j++; } $ven_i++; } ?> and then $ven_total should be the total I'm looking for. However, $ven_total just ends up being the first checkbox selected, and it ignores the rest. I am doing this correctly with the AJAX, displaying the total on the front end, but I don't know how to pass that on to the form submission. I'd rather not using GET and URL variables, because a user could type something into the URL and modify the count. Any idea what I'm doing wrong, or a better way to approach this that I would be able to understand? (Very much a novice programmer.)

    Read the article

  • Formula needed: Sort array to array-"snaked"

    - by aw
    After the you guys helped me out so gracefully last time, here is another tricky array sorter for you. 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 and render it 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 to have a "snake" later: // rearrange the array according to this schema 1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7 // the original array should look like this a = [1,2,3,4,12,13,14,5,11,16,15,6,10,9,8,7] Now I'm looking for a smart formula / smart loop to do that ticker = 0; rows = 4; // can be n cols = 4; // can be n 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++; } Thanks again for the help.

    Read the article

  • Finding position of each word in a sub-array of a multidimensional array

    - by Shreyas Satish
    I have an array: tokens = [["hello","world"],["hello","ruby"]] all_tokens = tokens.flatten.uniq # all_tokens=["hello","world","ruby"] Now I need to create two arrays corresponding to all_tokens, where the first array will contain the position of each word in sub-array of tokens. I.E Output: [[0,0],[1],[1]] # (w.r.t all_tokens) To make it clear it reads, The index of "hello" is 0 and 0 in the 2 sub-arrays of tokens. And second array contains index of each word w.r.t tokens.I.E Output: [[0,1],[0],[1]] To make it clear it reads,the index of hello 0,1. I.E "hello" is in index 0 and 1 of tokens array. Cheers!

    Read the article

  • Converting array to Drupal format

    - by theo
    Hi all, This statement gives me the value I want in Drupal (namely the last user role): global $user; return (end($user->roles)); however I need to convert it to this format: return array( 0 => array('value' => value for value), // You'll usually want to stop here. Provide more values // if you want your 'default value' to be multi-valued: 1 => array('value' => value for value), 2 => ... ); and I've got no idea how to (also, is this format a multidimensional array?)... Any ideas? Thanks for any help, Theo.

    Read the article

  • Prototype.js: How can i return an array without all the methods Prototypes extends Array with?

    - by Morten
    Hi! Is there a way to return a new version of an array/hash that does not contain all the methods/functions that prototype extends the array object with? Example: var myArray = $A(); myArray['test'] = '1'; myArray['test2'] = '2'; var myVariableToPassToAjax = myArray; If I debug myVariableToPassToAjax it looks like this: Array ( [test] = 1 [test2] = 2 [each] = function each(iterator, context) { .......... .......... } ...and all the other extended array functions ); Is there a way to solve this? :-/ Morten

    Read the article

  • display an array in html table

    - by Davi
    I have this array: Array ( [page] => Array ( [0] => add [1] => edit [2] => delete [3] => search ) [category] => Array ( [0] => add [1] => edit [2] => export ) ) And I want it to be displayed as a html table like this: Page - Category add - add edit - edit delete - export search search I tryed in many ways but didn't work, any solutions? Thank you

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >