arrays

Cannot understand how new or malloc does work with BYTE*

I trying to allocate memory for 10 bytes BYTE* tmp; tmp = new BYTE[10]; //or tmp = (BYTE*)malloc(10*sizeof(BYTE)); But after new or malloc operation length of *tmp more than 10 (i.e. '\0' char not in 10 position in tmp array) Why? ...

How can I make `new[]` default-initialize the array of primitive types?

Every now and then I need to call new[] for built-in types (usually char). The result is an array with uninitialized values and I have to use memset() or std::fill() to initialize the elements. How do I make new[] default-initialize the elements? ...

Is new int[10]() valid c++?

While trying to answer this question I found that the code int* p = new int[10](); compiles fine with VC9 compiler and initializes the integers to 0. So my questions are: First of all is this valid C++ or is it a microsoft extension? Is it guaranteed to initialize all the elements of the array? Also, is there any difference if I do new...

sort associative array PHP

Here's my array, how do I sort it by saleref? Array ( [xml] => Array ( [sale] => Array ( [0] => Array ( [saleref] => 12345 [saleline] => 1 [product] => producta ...

Is there a way to extract continuous feature in an 2D array

Say I have an array of number a <- c(1,2,3,6,7,8,9,10,20) if there a way to tell R to output just the range of the continuous sequence from "a" e.g., the continuous sequences in "a" are the following 1,3 6,10 20 Thanks a lot! Derek ...

Remove a child from an array in PHP?

Lets say I have this array: $queue = array("orange", "banana", 'apple', 'watermelon'); If I want to remove any of them,for example I want to remove banana, how to do it? ...

Sparse Array in C! How accomplish it? Can I alloc only parts of an array?

Hi guys! The first question is: "How I do a simple sparse array in C (with one dimension only)?" {with my own hands, without libraries.} And the last one: "Can I allocate only parts of an array?" like *array; then use malloc to allocate some mem for this; so, We free the index that we don't want. Can I do it? Thanks so much! ...

Good C++ array class for dealing with large arrays of data in a fast and memory efficient way?

Following on from a previous question relating to heap usage restrictions, I'm looking for a good standard C++ class for dealing with big arrays of data in a way that is both memory efficient and speed efficient. I had been allocating the array using a single malloc/HealAlloc but after multiple trys using various calls, keep falling fou...

How do I sort an array of custom classes?

I have a class with 2 strings and 1 double (amount). class Donator string name string comment double amount Now I have a Array of Donators filled. How I can sort by Amount? ...

How to find sum of elements from given index interval (i, j) in constant time?

Given an array. How can we find sum of elements in index interval (i, j) in constant time. You are allowed to use extra space. Example: A: 3 2 4 7 1 -2 8 0 -4 2 1 5 6 -1 length = 14 int getsum(int* arr, int i, int j, int len); // suppose int array "arr" is initialized here int sum = getsum(arr, 2, 5, 14); sum should be 1...

Creating nested arrays on the fly

I am trying to do is to loop this HTML and get a nested array of this HTML values that i want to grab. It might look complex at first but is a simple question... html <div class="configureData"> <div title="Large"> <a href="yellow" title="true" rel="$55.00" name="sku22828"></a> <a hre...

List of Big-O for PHP functions

After using PHP for a while now, I've noticed that not all PHP built in functions as fast as expected. Consider the below two possible implementations of a function that finds if a number is prime using a cached array of primes. //very slow for large $prime_array $prime_array = array( 2, 3, 5, 7, 11, 13, .... 104729, ... ); $result_arra...

C++ a class with an array of structs, without knowing how large an array I need

New to C++, and for that matter OO programming. I have a class with fields like firstname, age, school etc. I need to be able to store other information like for instance, where they have travelled, and what year it was in. I cannot declare another class specifically to hold travelDestination and what year, so I think a struct might be ...

Simulating pass by reference for an array reference (i.e. a reference to a reference) in Java

I was wondering, in java, is it possible to in anyway, simulate pass by reference for an array? Yes, I know the language doesn't support it, but is there anyway I can do it. Say, for example, I want to create a method that reverses the order of all the elements in an array. (I know that this code snippet isn't the best example, as the...

I want to use contents of String or Array in an If-else statement for iphone

I want to check to see if an array has "-" to activate a shipping method. I put "-" in since the array value will aways =2 and I need to IF ELSE by the contents. If the user doesn't not enter an address in the contents of the array looks like this: Root Array (2items) Item 1 String - Item 2 String - Here is the code for ...

string reverse without new array

hi can anybody tell me the error in this? #include<stdio.h> int main() { char a[]="abcdefgh"; int i=0; int n=strlen(a); char *first; char *second; char *c; *first=a[0]; *second=a[7]; for(i=0;i<=n/2;i++) { *c=*first; *first=*second; *second=*c; first...

how to get rid off garbage in array of chars?

hi, I'm writing a C program but I keep having problems with my array of chars. I keep getting garbage when I print it using prinf. here is an example of what I get when I print it: char at t.symbol is Aôÿ¿ char at tabl[0].symbol is A char at tabl[1].symbol is a char at tabl[2].symbol is a char at tabl[3].symbol is d char at tabl[4]...

A problem about in_array

Hi all, I have got a strange problem about in_array recently which I cannot understand. e.g. $a = array('a','b','c'); $b = array(1,2,3); if (in_array(0,$a)) { echo "a bingo!\n"; } else { echo "a miss!\n"; } if (in_array(0,$b)) { echo "b bingo!\n"; } else { echo "b miss!\n"; } I ran it on my lamp,and got a bingo! b...

PHP Sort Array By SubArray Value

I've got the following structue of array: Array ( [0] => Array ( [configuration_id] => 10 [id] => 1 [optionNumber] => 3 [optionActive] => 1 [lastUpdated] => 2010-03-17 15:44:12 ) ...

php weird bug where an array is not an array !

I've been going mad trying to figure out why an array would not be an array in php. For a reason I can't understand I have a bug in a smarty class. The code is this : $compiled_tags = array(); for ($i = 0, $for_max = count($template_tags); $i < $for_max; $i++) { $this->_current_line_no += substr_count($text_blocks[$i], "\n"); //...