Such as topic, have an excel spreadsheet, saved a m * n in the table data, add code can be read out in VC6.0 m * n all of the data, now in order to realize such a function, dynamic load n1 and n2 within the scope of a column of data, and the data into into the dynamic array, where 0 & lt; N1 & lt; N2 & lt; M, and find out all the elements in the dynamic array and, n1 and n2 here is through the dialog box of the edit control input, and seen some routines, I use like int * p=new int [n2 - n1 + 1] way to create a dynamic array, thought is simpler, but read the data one by one assignment, only the first array element has a value, behind of no value, seems to be address values, again and again to find problems, there is still no solution, consult the expert in the BBS
CodePudding user response:
You create a one-dimensional array According to your description I feel you should use a two-dimensional array
CodePudding user response:
Fyi:
# include & lt; stdio.h> #include #include Int * * newarr2d (int rows, int cols) { Int * * p, I;
P=(int) * * malloc (rows * sizeof (int *)); If (NULL==p) exit (1); For (I=0; iP=(int *) [I] malloc (cols * sizeof (int)); If (NULL==p [I]) exit (1); } return p; } Void deletearr2d (int * * p, int rows) { int i;
For (I=0; iFree (p [I]); } Free (p); } Int main () { Int * * arr2d, I, j, r, c;
R=4; C=5; //in the heap open up a two-dimensional array of int 4 x5 Arr2d=newarr2d (r, c); For (I=0; iFor (j=0; JArr2d [I] [j]=I * c + j; } } For (I=0; iFor (j=0; JPrintf (" % 2 d ", arr2d [I] [j]); } printf("\n"); } Deletearr2d (arr2d, r);
R=6; C=3; //in the heap open up a two-dimensional array of int 6 x 3 Arr2d=newarr2d (r, c); For (I=0; iFor (j=0; JArr2d [I] [j]=I * c + j; } } For (I=0; iFor (j=0; JPrintf (" % 2 d ", arr2d [I] [j]); } printf("\n"); } Deletearr2d (arr2d, r);