Question:
Please help me in multidimensional array using c++?
anonymous
2011-03-20 12:52:25 UTC
Please help me....i want to declare some multidimensional array but i have a problem with the declaration....i didnt know where i am wrong..Please help me....

This is a piece from my program...
i got an error when i want to declare Special array with integer data type...

* Message Error :
1. Non-Constant expression as array bound
2. '=' cannot convert from 'int [*][1]' to 'int'



#include
#include
#include

char *Entry, Letter, Choice[2];
int Ascii, len, Binary[8], Total;
void Convert();
int j = 0;
int Special;

void main()
{
Convert();
//return 0;
}

void Convert()
{
Entry = new char[501];
cout << "Enter Text To Convert(Up To 500 Chars): ";
cin.getline(Entry, 500);
len = strlen(Entry);

Special = new int[8][len];


}
Three answers:
The Phlebob
2011-03-20 15:20:56 UTC
The declaration for Special:



int Special;



isn't compatible with the attempt to assign of space to it:



Special = new int[8][len];



First, Special isn't being declared an array. Second, you have to use the new operator on a pointer, as you did with Entry.



You have to tell the compiler in the declaration that Special is going to be an array. Because you don't know beforehand how big the second dimension is going to be, you're going to have to figure out a way to handle that during the execution of the program. Using a pointer to int (int *Special) might be one way, but then you're going to have to calculate the row x column offsets by hand.



Hope that helps.
?
2016-11-14 04:39:20 UTC
i will only say which you're making use of basically a million-D arrays. So, dont call multi-dimensional arrays. i assume you have asked yet another question additionally in this subject remember in present day previous. What do you elect? i recommend you to take a 2-D to tutor participant place. you could initialize the arrays additionally. your applications implementations are no longer maximum suitable. setPosition getPosition all are no longer maximum suitable. in case you specify what rather you elect we are able to characterize
BoogyMan Messiah
2011-03-20 12:57:11 UTC
Try changing this: int Special;





to this: int[][] Special;


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...