arrays

Trimming blank spaces from a char array in C

My char array would be looking something like below, Org_arr[1first line text------2second line text----3third line-------4--------------------5fith line text------]; where '-' equal to blank spaces The above array contains the control code(0, 1, 2, 3..) after every 20 characters starting from 0-th place. I would like to convert th...

Are arrays or lists passed by default by reference in c#?

Do they? Or to speed up my program should I pass them by reference? ...

resizing array at runtime in vb.net

on my winform at runtime i will be resizing my array each time i add an element. so first i must resize to the size + 1, and then add a member to this index. how do i do this? ...

How to transfer a variable from a struct to a method ?

Hi All, Let's assume we have an array named "points" having the type of Point3D in a struct and want to use these points in a method. How to transfer from the struct to the method ? The following are from the code snippet. Regards Cemil public MeshGeometry3D GetMesh3D() { **(just here, we want to use the 3D points coming from the G...

Search for multiple occurrences of a value in a character array and then listing # of occurrences. VC++

I'm trying to write a small program that will generate a parity bit for Hex and Binary values pulled from an ASCII character array. I have a total of 3 character arrays. For example: const char *caASCII[] = {"A", "B", "C", ...}; const char *caASCIIBinary[] = {"01000001", "01000010", "01000011", ...}; const char *caASCIIHex[] = {"41", ...

Why are my arrays showing up as 0 in php?

I'm trying to make a file that creates a array of 3 strings, than randomly displays one of the three 5 times. Can someone tell me what I'm doing wrong? <?php $pk[0] = "PK Fire!<br/>"; $pk[1] = "PK Thunder!<br/>"; $pk[2] = "PK Freeze!<br/>"; for($i = 0; $i < 5; $i++) Echo "" + $pk[rand(0,2)] + ""; ?> ...

determine size of array if passed to function

Is it possible to determine the size of an array if it was passed to another function (size isn't passed)? The array is initialized like int array[] = { XXX } .. I understand that it's not possible to do sizeof since it will return the size of the pointer .. Reason I ask is because I need to run a for loop inside the other function wher...

Explaining benefits of an array to a lay person?

I develop code in our proprietry system using a scripting language that is unique to that system. Our director has allowed us to request enhancements to this language, which currently lacks user definable arrays. I need to write a concept brief on why we need arrays and how they can benefit us, however I need to explain it in a fashion t...

Output JSON array without the class name in every array element.

The default way to output JSON in rails is some thing like: Code: render :json => friends.to_json(:only => [:username, :avatar_file_name, :id ]) Output {"friends" : [{"user": {"avatar_file_name": "image1.jpg", "username": "user1", "id": 1}}, {"user": {"avatar_file_name": "image2.jpg", "username": "user2", "id": 2}}, ...

PHP - How to get object from array when array is returned by a function?

Hi, how can I get a object from an array when this array is returned by a function? class Item { private $contents = array('id' => 1); public function getContents() { return $contents; } } $i = new Item(); $id = $i->getContents()['id']; // This is not valid? //I know this is possible, but I was looking for a 1 li...

Iterating through a multidimensional array in Python

I have created a multidimensional array in Python like this: self.cells = np.empty((r,c),dtype=np.object) Now I want to iterate through all elements of my twodimensional array, and I do not care about the order. How do I achieve this? ...

View array in Visual Studio debugger?

Is it possible to view an array in the Visual Studio debugger? QuickWatch only shows the first element of the array. ...

Is there a way to initialize an array with non-constant variables? (C++)

I am trying to create a class as such: class CLASS { public: //stuff private: int x, y; char array[x][y]; }; Of course, it doesn't work until I change int x, y; to const static int x = 10, y = 10; Which is impractical, because I am trying to read the values of x and y from a file. So is there any way to initialize an a...

Why does .NET Array class copy so slow?

I was disappointed to find that Array.Clone, Array.CopyTo, and Array.Copy can all be beat by a simple 3-line manually coded for(;;) loop: for(int i = 0; i < array.Length; i++) { retval[i] = array[i]; } Say the base case for performing an operation a few million times on an array of some predetermined size takes 10 ...

how can I simply merge a hash into a new one?

I have a simple hash like so { "1234" => "5", "2345" => "6" } How can I create a new hash with both the keys and values in side it? Like so: { key_id = "1234", value_id = "5" }, { key_id = "2345", value_id = "6" } ...

DOM selection in jquery

Hi, i have a table, and i did sorting of that. Its execution time bad. I guess this is because of DOM manipulation. /* I m converting to array */ var rows = $table.find('tbody > tr').get(); $.each(rows, function(index, row){ /*then again to 2D array */ if(($(row).children('td').eq(0).attr('class').indexOf('collapse') != -1 ...

char array to LPCTSTR conversion in c

Does anyone know how to convert a char array to a LPCTSTR in c? Edit: For more reference, I need to add an integer to a string then convert that string to LPCTSTR for the first parameter of the windows function CreateFile(). This is the hardcoded example which I am currently using, but I need to be able to pass in any number to use as...

how to loop through this array in php

I want to loop through this array: $securePages=array("admin.php","addslot.php","classpost.php"); $pagename="admin.php" Then if admin.php is found then execute this code: header("location:index.php"); exit(); How would I put together this looping statement? ...

Quick Fix Java Error ArrayIndexOutOfBoundsException

Am I just to blind to see the solution? sampleSum = 0; for(int x : sampleWeights) sampleSum += x; population = new int[sampleSum]; int z = 0; for(int i = 0; i < nsamples; i++) for(int j = 0; j < sampleWeights[i]; j++) { population[z] = i; z++; } Any help is appreciated! Thanks! ...

How to sort a JSON array ?

I read in the following JSON object using ajax and store the object as an array: var homes = [ {"h_id":"3", "city":"Dallas", "state":"TX", "zip":"75201", "price":"162500"}, {"h_id":"4", "city":"Bevery Hills", "state":"CA", "zip":"90210", "price":"319250"}, {"h_id":"5", "city":"...