Bah, once again I am beat by the computer logic...
Anyone have an answer as to why it gives me an error: "Expected a constant expression at msg"
Here's the code,
const int INFOWND_SIZE = 4;
int msg_length[] = "Message";
double calc_amount = (double)msg_length/(double)INFOWND_SIZE;
int msg_amount = (int)ceil(calc_amount);
char msg[msg_amount][INFOWND_SIZE];
Anything unclear? eh.. let's take a look...
- declaring a constant int with the value 4
- divide length with size, giving a double
- declare variable int with a cast (int) to make sure it calculates int, and then do the ceil()
- declaring a char array with 2 dimensions, first one is the amount calculated, second is the size
Please try and give a simple answer that I can understand. :P
Constructive criticism, suggestions, anything that might optimize the code further is much appreciated, as long as you explain why.
//----------------------------------------------
Here's the whole code in context
const int INFOWND_SIZE = 51;
void new_message(char var[]){
COORD coord = {(infoffset.X+1), (infoffset.Y+1)};
int real_infownd_size = INFOWND_SIZE-4;
int msg_length = strlen(var);
if( msg_length >real_infownd_size ){
double calc_amount = (double)msg_length/(double)real_infownd_size;
int msg_amount = (int)ceil(calc_amount);
char msg[msg_amount][INFOWND_SIZE];
cout<<endl<<"length: "<<msg_length<<endl;
cout<<"MAXIMUM: "<<INFOWND_SIZE-4<<endl;
cout<<"amount of divs: "<<msg_amount<<endl;
}
}
This is a simple program I'm making, a sort of chat window, but not too complex yet. Anyway, at the start, I call the function with a parameter of 107. Rounded up it should be 3, the cout statement agreed, and it doesn't display a double value. Once I declare the variable named "msg_amount" as a const, it just piles up more errors...
The whole problem involves the section where I declare char msg[msg_amount][INFOWND_SIZE], where the compiler tells me it expected a const value. The whole idea of this is to take the string and divide it in sections so that the text won't overwrite other outputed stuff in the info window (infownd) since the window itself has a size.