problem about 2d-array-Collection of common programming errors


  • TotalJargon
    c# xna windows-phone-7.1 text-files 2d-array
    I’m attempting to create a 2D array of integers that load in data from a .txt file, however when it compiles this line of code: string line = stream.ReadLine(); it gives me the error in the thread title and also this:Attempt to access the method failed, System.IO.StreamReader..ctor(System.String)I understand there may be differences between using txt files between PC and WP7/360 however I am sure that it’s possible because an app my College tutor made used .txt files on his WP7 handset, what sor

  • jonobr1
    javascript matrix manipulation 2d-array
    So I found this thread that was extremely helpful in traversing an array diagonally. I’m stuck though on mirroring it. For example:var m = 3; var n = 4; var a = new Array(); var b = 0;for(var i = 0; i < m; i++) {a[i] = new Array(n);for(var j = 0; j < n; j++) {a[i][j] = b;b++;} }for (var i = 0; i < m + n – 1; i++) {var z1 = (i < n) ? 0 : i – n + 1;var z2 = (i < m) ? 0 : i – m + 1;for (var j = i – z2; j >= z1; j–) {console.log(a[j][i – j]);} }Console reads [[0],[4,1],[8,5,2],[9,

  • MrMormon
    c++ variable-assignment 2d-array
    I’m sorry if I didn’t pick a descriptive or concise name. A lot of questions sound similar, but I haven’t been able to find what I’m looking for. What I want to do is store a 2D array of pointers somewhere and assign a variable in some object to that array to be able to access it.Here’s some example code that has the same compile error I’m getting with a bigger project.#include <iostream> using namespace std; struct X{float n, * b[8][8];X(){n = 1;b[1][5] = &n;cout << *(b[1][5]) &

  • Diego
    javascript arrays multidimensional-array 2d-array
    I have been reading online and some places say it isn’t possible, some say it is and then give an example and others refute the example, etc. How do I declare a 2 dimensional array in JavaScript? (assuming it’s possible) How would I access its members? (myArray[0][1] or myArray[0,1]?)Thanks

  • Michael Dorgan
    c char 2d-array realloc
    I have following codeint wordLenght = 256, arrayLength = 2, i = 0, counter = 0;char **stringArray = NULL; stringArray = calloc(arrayLength, sizeof(*stringArray));for(counter; counter<wordLenght; counter++) stringArray[counter] = calloc(wordLenght, sizeof(stringArray));while(1){printf(“Input: “);fgets(stringArray[i], wordLenght, stdin);printf(“stringArray[%d]: %s\n”, i, stringArray[i]);if(i == arrayLength){printf(“Reallocation !!!\n”);arrayLength *= 2;stringArray = realloc(stringArray, arrayLe

  • nazar_art
    java file csv refactoring 2d-array
    I need read data from csv file and much more convinience for me is put there to 2D array (to my mind it’s easiest way to work with this “schedule” data). Each file line contained information in following format:Instructor, Course, Group, Student, Resultas follows example:Paul Schwartz,Introduction to Computer Architecture,I1,Ben Dunkin,88 Muhamed Olji,Object Oriented Programming,I4,Mike Brown,73But my code needs some simplify. But I don’t know how to make it easier and ask of You.Code:private St

  • LihO
    c++ linux arrays pointers 2d-array
    Here is my code in c++int** a; try{a = new int*[m];for(int i = 0; i<m;i++)a[i] = new int[n]; }… Right now i am initializing the above using for loops as follows:for(int i = 0; i<m; i++)for(int j = 0; i<n; j++)a[i][j] = 0;I am trying to improve performance and hence thought using memset would be a good idea . So modified my code to use memset instead of for loop as follows:memset(a, 0, sizeof(a[0][0]) * m * n);But i get Segmentation fault on executing this . Can anybody help me figure

  • pilotcam
    c++ pointers segmentation-fault 2d-array
    I am facing an issue with a 2D array of pointers. It compiles with no errors, however when I try to run the file, all I get is a single line saying I have a segmentation fault.My header file:#ifndef __TWODARRAY_H__ #define __TWODARRAY_H__template <typename T> class TwoDArray {private:T** theArray;int numRows;int numCols;T defSpace;public:TwoDArray<T> (int r, int c, T def);~TwoDArray<T>();void insert(int r, int c, T value);T access(int r, int c);void remove(int r, int c);void pr

  • syb0rg
    c malloc 2d-array double-pointer
    In C, I am using a char ** to hold a series of strings.Here is my code:char ** c; //now to fill c with data ????//cannot change: printf (“%*s%s”, 0, “”, *c); while (*++w)printf (” %s”, *c);I do not know how to fill c with data. What is the proper way? I cannot change the 3 printing lines because they are in an external function.

  • user2402501
    c function pointers multidimensional-array 2d-array
    I’m having a problem with my program. I need my program to read from a text file, the first consists of the dimensions of the 2d array the rest is the contents of the array. I have coded the readWord function which reads from textfiles and it works but when i do anything on the main function with the array it crashes. Please could you help.int main(){int num_it, cols, rows;char** myworld;num_it = readWorld(myworld,&cols, &rows);myworld[1][2]=’x’;/*it crashes when i make this statement*/}

  • pxlbrnd
    c malloc 2d-array
    I already searched for an answer here, but I couldn’t find something that suits my case.I have a function make_array(), which generates a 2-dimensional array, and has to fill it with zeros. When calling this function in main() and printing the values, there’s a strange output, which is non-reproducible on other machines…[…] Valuearray[0][13]: 0 Valuearray[0][14]: 65 Valuearray[0][15]: 0 […]The rest of the array contains Zeros. Searching for an answer I randomly changedArray[i][j] = 0;t

  • Mooing Duck
    c++ 2d-array
    As in the title.I’m confused between them.char var[3][15]= {“Hello_world!”, “good”, “bad”}; // as known this is for an 2D array. char *var[3]= {“Hello_world!”, “good”, “bad”}; // and this I think also 2D array, but how.What’s the difference between them? What is the cases to use that or that?I’m sorry but I have big confusion between them.

  • Enjoy coding
    javascript dynamic 2d-array
    I am trying to use 2 dimensional array in javascript for storing strings. But I am not able to get the values correctly. Below is my code.var commentstore=new Array();function creating(id,day){if(commentstore[day,id] != null){alert(“It already exists: commentstore[“+day+”][“+id+”]”+commentstore[day,id] );var textinput=”<div id=’closeit’>Comments:<input type=’text’ name=’comm[“+day+”] [“+id+”]’ value='”+commentstore[day,id]+”‘/></div><div id=’closing’ onclick=’closecomment(“

  • Who Cares
    c++ delete 2d-array
    Can some one tell me what is wrong in the for loop? When I run it, it interrupts. I tried to debug to see what is wrong, i noticed that in the for loop it just stops :\#define MAX_POPULATION 64 float **tr_pop;//Tournament candidates float **matingPool;//Mating pool tr_pop=new float *[m]; matingPool=new float *[m]; for(l=0;l<m+1;l++)//allocating {tr_pop[l]=new float[MAX_POPULATION];matingPool[l]=new float[MAX_POPULATION]; } for ( int r = 0; r < row; ++r )//deleting {delete [] matingPool[r];

  • josh3736
    javascript arrays loops 2d-array
    I am trying add on dimension of an array together into a variable using a for loop. I have then using alert to show a pop up box with a value in it just to make sure it is working however the popup box says undefined instead of the value i was expecting. Any ideas? var actor = new Array [[20,30,10,30,10],[10,20,40,30,0],[10,10,20,40,20]]var n1 = 0; for (var i = 0; i < 6; i++) { n1 = n1 + actor[0][i]; }

  • user1847706
    c 2d-array indexes
    I’m new in C programing and I need to use a 2D integer array (a matrix). For example, I do this:void main(){int matrix[2][2] = { {0,1}, {2,3} };printf(“%i”, matrix[4][4]); /*Here should be an index error, but that doesn’t happen*/ }What is wrong?

  • HalfBit
    arrays string actionscript-3 dynamic 2d-array
    I am trying to copy a 2D array in a temporary array to a permanent one. The problem is that the array it’s trying to copy to is dynamic.I was looking for a way to get string (the new arrays name) to act as the arrays actual name, not the value of any part of the array. I have looked around and this is roughly what I came to:(this[“dynamicArrayName”]) = tempArray;or(this[variableWithName]) = tempArray;(not even sure thats the best way to copy a 2D array).However, this doesn’t work :(. It comes up

  • Jes Uppy
    c file-io for-loop 2d-array
    I’m having a problem fixing this infinite loop. I’ve done some tests so I’m pretty sure the loop isn’t when reading the file. Right after “printReportHeading();” is a for loop. I am pretty sure that is what is causing the issues. How would I go about fixing this. Is it something to do with initialization of the 2 dimensional array?Code:int main(void){FILE* fileIn;FILE* printFile;float average;char letterGrade;int wholeArray [MAX_STUDENTS][MAX_PROFILE],letterFreq[5];printInstructions();fileIn =

  • Eric
    c++ 2d-array readfile
    i am doing read file in c++ and this is my code : #include <iostream> #include <fstream> #include <algorithm> #include <climits> using namespace std;int main() { int row=0; int col=0; ifstream inputFile; int arr[16][5];inputFile.open(“hdtt4req.txt”);if(inputFile.is_open()) {inputFile >> arr[row][col];for (row = 0; row < 16; row++) {for (col = 0; col < 5; col++) {cout <<“hi”; //arr[row][col];cout << endl;}}}return 0; }and this is the file that i wan

  • stewartbracken
    c compiler-errors 2d-array
    I’ve been perusing similar questions to mine for a couple of days but still haven’t found a solution. Thanks any any help:I have two files, one containing methods for dealing with rational numbers and one that handles them in a 2 dimensional array. My problem is matrix.c doesn’t recognize the fraction structure in contained in fraction.c. I believe my problem is somehow related to the way I declared my 2d array.In fraction.c:struct fraction {int integer;int num;int den; }; typedef struct fractio

  • 2dawolf
    javascript 2d-array
    Does anyone know why this gives an error? I’ve been trying at it way too long and I can’t seem to figure it out. It errors with “cannot read property 0 of undefined”, but it is clearly defined. (or so I think)var categorySix = [[“test”][“test2”],[“testing”][“one”],[“two”][“three”]]; document.write(categorySix[0][0]);

Originally posted 2013-11-27 12:10:34.