virtual topology design

why the following errors have occured ..........

c2087: Missing Subscript

c2133: Unknown size

c2059 :Syntax Error
There's no enough information to discern the cause of the error. We'd need the full error and code, probably.

1. You are missing a subscript somewhere.
2. The size is unknown for something somewhere.
3. Your syntax is bad - contains an error somewhere.

Why are you the age that you are?
You tell us, then we will all know.......
How many people do know that are telepathic?
Is my sister taller than you?
Cliches until the cows come home.
The sum of apples and cars equals how many houses?
At what point does a question become so vague that no one can find an answer?

Have you heard of Google or wiki, or read any tutorials, a text book, or not slept through your lecture?

Have you actually written any code, or is this you star gazing about what future errors you might have?

Consider thinking about how to ask questions effectively.

Have we reached a new depth of Y-Gen laziness? (sorry for the obvious mass generalisation)

Sorry, couldn't help myself for a bit of comedy - silly questions, silly answers :D .

No idea about your problem unless you show us the code.

Make sure you use code tags - use the <> button on the right under formatting.
cout<< "Insert the maximum number of hops of the routing algorithm used :";
cin>> num_of_hops;
cout << endl << "number of paths : " << num_of_paths << endl;
int path_matrix[][];
path_matrix[num_of_paths][num_of_hops + 1];
float path_length[]; // The total length of each path
path_length[num_of_paths];

error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2133: 'a' : unknown size
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
i am unable to execute the array if the subscript value is obtained at the run time..i.e the value of the array index is dynamic and depends on the users input........
i am unable to execute the array if the subscript value is obtained at the run time


That's right, the array size must be a constant known at compile time.

Just so you know for future reference about arrays:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//better to do this than use magic numbers in the code
const unsigned int NumOfPaths = 10;
const unsigned int NumOfHops = 10;

int path_matrix[][]; //does not work unless there is an initialisation list in braces
                                //because the compiler counts how things there are

path_matrix[num_of_paths][num_of_hops + 1];

int PathMatrix[NumOfPaths][NumOfHops]; //now it's ok size and type is known

float path_length[]; // The total length of each path
path_length[num_of_paths]; //combine these 2 lines

float PathLength[NumOfPaths]; //Ok - size and type known


You need to use some other STL container which automatically gets larger (they have push_back and insert functions), if you want to set the size at run time.

Hope all goes well.
According to my code the no of paths have to be generated based on the user inputs only.I cant set that as 10 or some other constant value.
The code I posted was an example of how to use arrays.

For your program, I suggested using an STL container that can grow automatically when you add things to it.
Or you can use dinamically allocated arrays:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

int main()
{
    int count;
    std::cin >> count; //Get size of an array
    int* x = new int[count]; //Create new array of size count and make x point to it

//Initializating all array elements to zero
    for(int i = 0; i < count; ++i)
        x[i] = 0;

//Setting first and last array elements to 6 and 2 respectively
    x[0] = 6;
    x[count-1] = 2;

//outputting array
    for(int i = 0; i < count; ++i)
        std::cout << x[i] << '\n';
    std::cout << std::endl;

    return 0;
}
Last edited on
can u give some examples for dynamically allocating 2d array.
Sure:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>

int main()
{
    int rows, cols;
    std::cin >> rows >> cols; //Get size of an array

    int** x = new int* [rows];
    for(int i = 0; i < rows; ++i)
        x[i] = new int[cols];

//Initializating all array elements to zero
    for(int i = 0; i < rows; ++i)
        for(int j = 0; j < cols; ++j)
            x[i][j] = 0;

//Setting first and last array elements to 6 and 2 respectively
    x[0][0] = 6;
    x[rows-1][cols-1] = 2;

//outputting array
    for(int i = 0; i < rows; ++i) {
        for(int j = 0; j < cols; ++j)
            std::cout << (x[i][j]) << ' ';
        std::cout << std::endl;
    }

    return 0;
}

Output:
4 4
6 0 0 0
0 0 0 0
0 0 0 0
0 0 0 2

Last edited on
thank u MiiNipaa
Topic archived. No new replies allowed.