FAQ Database Discussion Community


Handling two or more select elements in one PHP form

php,html,forms,dynamic-arrays
I'm creating a HTML form that had a dynamically-generated list of select inputs. I'd like to cycle through these inputs (in the $_POST array) with a foreach block and make updates in the DB based on the information in each of these inputs. I know I have to name each...

Invalid read of size 4 on fscanf

c,arrays,valgrind,dynamic-arrays,fscanf
Running my program through valgrind, I'm getting an invalid read of size 4 error in the following code (I think at the line where fscanf is called) Important Info: numIntegers is the maximum number of integers that can be read, while numsInFile specifies the amount of integers present in the...

C++ Sectioning and Comparing a 2d Dynamic Array

c++,dynamic-arrays
I'm working on problem for a class that requires we use 2d dynamic arrays to get integers as each entry per array 'block' and save it. It must be able to take any size of array, all of which gets inputted from the user when the program gets ran. Then,...

Will dynamic arrays in fields of Delphi objects be automatically deallocated/freed when the object is destroyed?

delphi,destructor,dynamic-memory-allocation,dynamic-arrays
If I have a Delphi object containing a field with a dynamic array (containing for example strings), as follows: TClassWithDynArrayField = class(TObject) public some_dyn_array : array of string; end; will this array (and/or the contents of it) be automatically deallocated/freed when the object is destroyed, or will I have to...

Getting index of a certain element in a 2D numpy array

python,numpy,multidimensional-array,indexing,dynamic-arrays
I'm new to python so I need some help with this: I have 2D array of numbers that represent density of a circle of material in a space and I want to locate the centre. So I want to get the index of the numbers representing the diameter and then...

Freeing specific element from dynamically allocated array of structs

c,struct,dynamic-memory-allocation,dynamic-arrays
I have a simple struct s_person and constructor(int number) that takes the number of s_person we want to construct and returns a pointer to it. In this example I have constructed 2 s_person, and assigned values to their attributes, name. And it works. #include<stdio.h> #include<stdlib.h> #define MAX_NAME 50 typedef struct...

Array.every returns false instead of true

javascript,arrays,function,dynamic-arrays
I'm working on something and I wrote this code that seems to return false instead of true: function checkValidUsers(validUsers) { var validIds = validUsers.map(function (user) { return user.id; }); return function (users) { var ids = users.map(function (user) { return user.id; }); return ids.every(function (id) { return id in validIds;...

Sort JSON objects and append to html using javascript/JQM

javascript,json,html5,jquery-mobile,dynamic-arrays
First time using JSON and total beginner at javascript / JQM I am trying to read a JSON file, sort it by country name ie title and display in a listview. I am not sure if I am overcomplicating things by trying to use a two dimensional array to sort....

C program Strings Example how come the result is 98?

c,string,dynamic-arrays,c-strings
C program Strings Example how come the result is 98? #include <stdio.h> int main() { char s[]="%d%d%d"; int a=9,b=8,c=5; printf(s+2,a,b,c); return 0; } ...

Need to read a file, of any extension one byte at a time XE5 into dynamic array

delphi,delphi-xe5,dynamic-arrays,tfilestream
I already tried to read the file into a TFileStream but that is where I got stuck the file is inserted into the TFileStream but I am unable to read the bytes of the file, I haven't programmed in a while, please help me. I also tried to read it...

Accessing the values of map from its key using pointer to map

c++,pointers,hashmap,dynamic-arrays,unordered-map
I want to dynamically allocate an array of pointers to an unordered_map in C++. The std::unordered map has been typedef as 'dictionary'. dict_array= ( dictionary **) calloc(input_size, sizeof(dictionary*)); Now I want to access the individual hashmaps, and for each individual hashmap (mydict), I want to access the values using some...

How do I iterate over *all* values in an array that grows while iterating?

php,loops,foreach,iteration,dynamic-arrays
The example below won't work because foreach works on a copy of the array, but it shows conceptually what I want to achieve. $items = array('a', 'b', 'c', 'd'); foreach ($items as $i) { echo $i; if ($i === 'c') { $items[] = 'e'; } } I want this to...

Remove values from an array in-place without using extra memory

python,arrays,algorithm,dynamic-arrays
I want to remove value x from an array and I have the following constraints: I can only traverse the array once No extra memory/data structures are allowed so that a = [1, 2, 'x', 3, 4, 5] becomes [1, 2, 3, 4, 5, None] The case with only one...

Indexer and reference type for dynamic arrays in Ada

indexing,ada,dynamic-arrays,reference-type
I have the following spec: generic type Value_Type is private; package Containers.Arrays is type Static_Array is array(Positive range <>) of Value_Type; type Static_Array_Access is access all Static_Array; type Dynamic_Array is tagged private; function Length(Self : Dynamic_Array) return Natural with Inline; function "&"(Left : Dynamic_Array; Right : Value_Type) return Dynamic_Array; private...

dynamically allocate string literal

c++,dynamic,dynamic-arrays
I was wondering if it is possible to dynamically allocate a string literal? I know you are able to do char * letter = new char('b'); but is it possible to allocate a string literal like that For example: char * letter = new char("Hello"); ...

Create a dynamic array of strings that will scale upon being filled up

c,arrays,string,dynamic-arrays,realloc
Okay, so I'm reading though a txt file and storing each item by new line into an array of strings. The only problem is, I need to resize this array by 5 whenever it is close to filling up. Input looks something like this, except a lot larger CSE 1104...

Passing Array Index numbers from PHP to Javascript

javascript,php,dynamic-arrays
new to JS and PHP and modifying a slideshow script to dynamically display contents of three different directories. Pretty much keeping things simple to start off with. One problem I have is that the script I am modifying used the following static code to fill the javascript array: variableslide[0]=['team_a/blank.jpg'] variableslide[1]=['team_a/ford.jpg']...

Delphi XE7 Android Creating Thread Error After Running about 2000000 times

android,multithreading,delphi,dynamic-arrays
thanks ahead for your time. Simple code post at first. code of TSubThread TSubThread = class(TThread) protected procedure Execute; override; public constructor Create; destructor Destroy; override; end; procedure TSubThread.Execute; begin // do nothing end; constructor TSubThread.Create; begin inherited Create(True); Self.FreeOnTerminate:= False; end; code of TMainThread TMainThread = class(TThread) private FCounterOK,...

Appending a dynamic array in VBA

vba,dynamic-arrays
I'm looping through a named range and appending an array based on if the cell is empty or not. I'm not too familiar with arrays in VBA, so perhaps my logic is incorrect. The code keeps overwriting the 1st element in the array and it never gets incremented. I"m not...

How can I implement 5 dimensional array in one for loop in julia?

arrays,loops,julia-lang,dynamic-arrays
function prealloc() situation=zeros(Int64,3^5,5); i=1; for north=0:2 for south=0:2 for east=0:2 for west=0:2 for current=0:2 situation[i,:]=[north, south, east, west, current] i+=1 end end end end end situation end prealloc() How can I implement this code on one for loop or in only one loop how I use nested loops to do...

Possible to both return and free a dynamically allocated array in C?

c,function,malloc,dynamic-arrays
Is it possible to both return and free a dynamically allocated array? int *mycopy(int *from, int len) { int i; int *to; to = malloc(len*sizeof(int)); for(i = 0; i < len; ++i) { to[i] = from[i] } return to; // how do I free the "to" array? // do i...

How to compare the input of user(here username) to the array of substrings and produce output in a label of same page?

javascript,arrays,string,html5,dynamic-arrays
I want a code in javascript. I have an input field in HTML5 and user enters his name in it and as per condition: The first 3 letters of his name has to be compared with an array of strings like("Chu, Che, Cho, La,Lee, Lu, Le, Lo,A, E, U, Ea")...

Trouble with creating/sizing a dynamic array (pointer) in C [duplicate]

c,arrays,pointers,dynamic-arrays
This question already has an answer here: C - SizeOf Pointers 4 answers What this does should be quite obvious, but my userLetters array is incorrectly sized... Whats going on?? I thought to get the size of the array you multiply the size of the elements by the amount...

How to access array of flexible arrays in cache friendly manner?

c,arrays,c99,dynamic-arrays,flexible-array-member
I have records with flexible array member typedef struct record { unsigned foo; signed bar; double number[]; } record; I have multiple records with the same amount of numbers so I can arrange them in array. I would like to allocate them into one continuous memory space. const unsigned numbers...

How do I dynamically allocated/grow an array of strings in C++?

c++,dynamic-arrays
Looking around I have found what I thought were to be solutions to my problem. Right now I am trying to read from a txt file. snippet from the file: 11111,"random phrase" 11123,"this is nonsense" 13212,"silly words" int arraylen = 2; string line, field; string* num = new string[arraylen]; string*...

glib how address to index g_ptr_array

c,glib,gnome,dynamic-arrays
I have 3 structures and I use GNOME glib library to have dynamic array. typedef struct Neuron { //number of inputs into neuron int NumInputs; //growing array of weights for each input GArray* ArrWeight; }neuron; typedef struct NeuronLayer { //number of neurons in layer int NumNeurons; //growing array of neurons...

Dynamically Allocated 2D-Array not initializing

c,arrays,multidimensional-array,malloc,dynamic-arrays
This code is supposed to allocate, initialize and print a 2-D array. For some reason depending on the value of N the 4th column has different values. (Everything should be 0). int N = 10; int **A; int i, j; A = malloc(N * sizeof(int *)); for (i = 0;...

triangular array in C

c,arrays,dynamic-arrays
Anyone know how to create triangular array in C? I tried to use malloc, firstly for first "dimension" and then i used for loop to create second dimension with malloc, but my leading teacher said that this isn't correct. int **price_of_diamond, i, j; price_of_diamond=malloc((count*sizeof(int))); for(i=0;i<conut;++i){ price_of_diamond[i]=malloc((i-1)*sizeof(int)); } Tip for the...

how do I delete allocated memory and still return its value from method

c++,dynamic-arrays,c-strings
I have this function as part of a class I am writing: const char* sockets::TCPSocket::doRecv(int flags) { char* incomingDataBuffer = new char [this->bufferSize]; ssize_t bytesReceived = recv(this->filedes, incomingDataBuffer, this->bufferSize, flags); // TODO set timeout - If no data arrives, the program will just wait here until some data arrives. if...