{"id":1637,"date":"2022-08-30T15:18:11","date_gmt":"2022-08-30T15:18:11","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/problem-about-2d-array-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:18:11","modified_gmt":"2022-08-30T15:18:11","slug":"problem-about-2d-array-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-2d-array-collection-of-common-programming-errors\/","title":{"rendered":"problem about 2d-array-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/4a1dde8952b06b74e5d38543d96e407d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nTotalJargon<br \/>\nc# xna windows-phone-7.1 text-files 2d-array<br \/>\nI&#8217;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&#8217;s possible because an app my College tutor made used .txt files on his WP7 handset, what sor<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/cb164af375db3ef7c3fc640d0d00ef73?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\njonobr1<br \/>\njavascript matrix manipulation 2d-array<br \/>\nSo I found this thread that was extremely helpful in traversing an array diagonally. I&#8217;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 &lt; m; i++) {a[i] = new Array(n);for(var j = 0; j &lt; n; j++) {a[i][j] = b;b++;} }for (var i = 0; i &lt; m + n &#8211; 1; i++) {var z1 = (i &lt; n) ? 0 : i &#8211; n + 1;var z2 = (i &lt; m) ? 0 : i &#8211; m + 1;for (var j = i &#8211; z2; j &gt;= z1; j&#8211;) {console.log(a[j][i &#8211; j]);} }Console reads [[0],[4,1],[8,5,2],[9,<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/a261141f44aa61c8fab8270dc448e429?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMrMormon<br \/>\nc++ variable-assignment 2d-array<br \/>\nI&#8217;m sorry if I didn&#8217;t pick a descriptive or concise name. A lot of questions sound similar, but I haven&#8217;t been able to find what I&#8217;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&#8217;s some example code that has the same compile error I&#8217;m getting with a bigger project.#include &lt;iostream&gt; using namespace std; struct X{float n, * b[8][8];X(){n = 1;b[1][5] = &amp;n;cout &lt;&lt; *(b[1][5]) &amp;<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8a1092162e472b9b496ed68d4750f66d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nDiego<br \/>\njavascript arrays multidimensional-array 2d-array<br \/>\nI have been reading online and some places say it isn&#8217;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&#8217;s possible) How would I access its members? (myArray[0][1] or myArray[0,1]?)Thanks<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e5b251b4ac8f0cb7942587ee8077cddb?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMichael Dorgan<br \/>\nc char 2d-array realloc<br \/>\nI have following codeint wordLenght = 256, arrayLength = 2, i = 0, counter = 0;char **stringArray = NULL; stringArray = calloc(arrayLength, sizeof(*stringArray));for(counter; counter&lt;wordLenght; counter++) stringArray[counter] = calloc(wordLenght, sizeof(stringArray));while(1){printf(&#8220;Input: &#8220;);fgets(stringArray[i], wordLenght, stdin);printf(&#8220;stringArray[%d]: %s\\n&#8221;, i, stringArray[i]);if(i == arrayLength){printf(&#8220;Reallocation !!!\\n&#8221;);arrayLength *= 2;stringArray = realloc(stringArray, arrayLe<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/zMjyh.jpg?s=32&amp;g=1\" \/><br \/>\nnazar_art<br \/>\njava file csv refactoring 2d-array<br \/>\nI need read data from csv file and much more convinience for me is put there to 2D array (to my mind it&#8217;s easiest way to work with this &#8220;schedule&#8221; 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&#8217;t know how to make it easier and ask of You.Code:private St<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/HU4wF.jpg?s=32&amp;g=1\" \/><br \/>\nLihO<br \/>\nc++ linux arrays pointers 2d-array<br \/>\nHere is my code in c++int** a; try{a = new int*[m];for(int i = 0; i&lt;m;i++)a[i] = new int[n]; }&#8230; Right now i am initializing the above using for loops as follows:for(int i = 0; i&lt;m; i++)for(int j = 0; i&lt;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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/70e63bfd35d009bf5b59d92bf721aeb8?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\npilotcam<br \/>\nc++ pointers segmentation-fault 2d-array<br \/>\nI 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 &lt;typename T&gt; class TwoDArray {private:T** theArray;int numRows;int numCols;T defSpace;public:TwoDArray&lt;T&gt; (int r, int c, T def);~TwoDArray&lt;T&gt;();void insert(int r, int c, T value);T access(int r, int c);void remove(int r, int c);void pr<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/XpiU6.jpg?s=32&amp;g=1\" \/><br \/>\nsyb0rg<br \/>\nc malloc 2d-array double-pointer<br \/>\nIn 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 (&#8220;%*s%s&#8221;, 0, &#8220;&#8221;, *c); while (*++w)printf (&#8221; %s&#8221;, *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.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/026db2f9f7faceeed970ba2ccabe8097?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser2402501<br \/>\nc function pointers multidimensional-array 2d-array<br \/>\nI&#8217;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,&amp;cols, &amp;rows);myworld[1][2]=&#8217;x&#8217;;\/*it crashes when i make this statement*\/}<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/a35a7e33277becb2da29624d054c0a46?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\npxlbrnd<br \/>\nc malloc 2d-array<br \/>\nI already searched for an answer here, but I couldn&#8217;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&#8217;s a strange output, which is non-reproducible on other machines&#8230;[&#8230;] Valuearray[0][13]: 0 Valuearray[0][14]: 65 Valuearray[0][15]: 0 [&#8230;]The rest of the array contains Zeros. Searching for an answer I randomly changedArray[i][j] = 0;t<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/a0638389439eea6b5dc936abccbe3c68?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMooing Duck<br \/>\nc++ 2d-array<br \/>\nAs in the title.I&#8217;m confused between them.char var[3][15]= {&#8220;Hello_world!&#8221;, &#8220;good&#8221;, &#8220;bad&#8221;}; \/\/ as known this is for an 2D array. char *var[3]= {&#8220;Hello_world!&#8221;, &#8220;good&#8221;, &#8220;bad&#8221;}; \/\/ and this I think also 2D array, but how.What&#8217;s the difference between them? What is the cases to use that or that?I&#8217;m sorry but I have big confusion between them.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/4ac7cc77265565c335c7a0a9f7e30660?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nEnjoy coding<br \/>\njavascript dynamic 2d-array<br \/>\nI 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(&#8220;It already exists: commentstore[&#8220;+day+&#8221;][&#8220;+id+&#8221;]&#8221;+commentstore[day,id] );var textinput=&#8221;&lt;div id=&#8217;closeit&#8217;&gt;Comments:&lt;input type=&#8217;text&#8217; name=&#8217;comm[&#8220;+day+&#8221;] [&#8220;+id+&#8221;]&#8217; value='&#8221;+commentstore[day,id]+&#8221;&#8216;\/&gt;&lt;\/div&gt;&lt;div id=&#8217;closing&#8217; onclick=&#8217;closecomment(&#8220;<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8c4facfc52cd22c334e7e9fbfd9bee98?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nWho Cares<br \/>\nc++ delete 2d-array<br \/>\nCan 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&lt;m+1;l++)\/\/allocating {tr_pop[l]=new float[MAX_POPULATION];matingPool[l]=new float[MAX_POPULATION]; } for ( int r = 0; r &lt; row; ++r )\/\/deleting {delete [] matingPool[r];<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/ce4c9b2df2d704c7d54ab740de2d54af?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\njosh3736<br \/>\njavascript arrays loops 2d-array<br \/>\nI 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 &lt; 6; i++) { n1 = n1 + actor[0][i]; }<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9645b47ffdc35685a477a2acd23f090e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser1847706<br \/>\nc 2d-array indexes<br \/>\nI&#8217;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(&#8220;%i&#8221;, matrix[4][4]); \/*Here should be an index error, but that doesn&#8217;t happen*\/ }What is wrong?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/43wp4.png?s=32&amp;g=1\" \/><br \/>\nHalfBit<br \/>\narrays string actionscript-3 dynamic 2d-array<br \/>\nI am trying to copy a 2D array in a temporary array to a permanent one. The problem is that the array it&#8217;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[&#8220;dynamicArrayName&#8221;]) = tempArray;or(this[variableWithName]) = tempArray;(not even sure thats the best way to copy a 2D array).However, this doesn&#8217;t work :(. It comes up<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f79fb25cc64dc842d37310c09df6e8d5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJes Uppy<br \/>\nc file-io for-loop 2d-array<br \/>\nI&#8217;m having a problem fixing this infinite loop. I&#8217;ve done some tests so I&#8217;m pretty sure the loop isn&#8217;t when reading the file. Right after &#8220;printReportHeading();&#8221; 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 =<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/1074f0a031cca12280359231a87662af?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nEric<br \/>\nc++ 2d-array readfile<br \/>\ni am doing read file in c++ and this is my code : #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;algorithm&gt; #include &lt;climits&gt; using namespace std;int main() { int row=0; int col=0; ifstream inputFile; int arr[16][5];inputFile.open(&#8220;hdtt4req.txt&#8221;);if(inputFile.is_open()) {inputFile &gt;&gt; arr[row][col];for (row = 0; row &lt; 16; row++) {for (col = 0; col &lt; 5; col++) {cout &lt;&lt;&#8220;hi&#8221;; \/\/arr[row][col];cout &lt;&lt; endl;}}}return 0; }and this is the file that i wan<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7d837068a87b2b7bc125368dac781e88?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nstewartbracken<br \/>\nc compiler-errors 2d-array<br \/>\nI&#8217;ve been perusing similar questions to mine for a couple of days but still haven&#8217;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&#8217;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<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/3eea1f9f37894182069efec852e03056?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\n2dawolf<br \/>\njavascript 2d-array<br \/>\nDoes anyone know why this gives an error? I&#8217;ve been trying at it way too long and I can&#8217;t seem to figure it out. It errors with &#8220;cannot read property 0 of undefined&#8221;, but it is clearly defined. (or so I think)var categorySix = [[&#8220;test&#8221;][&#8220;test2&#8221;],[&#8220;testing&#8221;][&#8220;one&#8221;],[&#8220;two&#8221;][&#8220;three&#8221;]]; document.write(categorySix[0][0]);<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-11-27 12:10:34. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>TotalJargon c# xna windows-phone-7.1 text-files 2d-array I&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1637","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1637"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1637\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}