arrays

Hello,

Everytime I try to run this code, it compiles with no errors. but when I run it it gives a runtime error.

The array demand which is checked if it isnt equal to zero is already filled with numbers.

What im trying to do is creat anthoer array "nodes" in a list way according to the condition I gave.

The error says that the problem is at line 8 in code below.

Thank you,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 int counter_i;
  int nodes[50][2];

	counter_i=0;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(demand[i][j]!=0){
        nodes[counter_i][0]=i;
        nodes[counter_i][1]=j;
        counter_i++;
      }
    }
    counter_i++;
  }

    for(i=0;i<50;i++){
   	 for(j=0;j<2;j++){
     	printf(" %d:",nodes[i][j]);
        }
        printf("\n\n");
        }
1
2
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){


What is 'n'?

You probably shouldn't be using 'n' for both dimensions anyway becaues each dimension is a different size. perhaps you meant to do this:

1
2
  for(i=0;i<50;i++){
    for(j=0;j<2;j++){
the array demand is [n][n] n=18.

so im using "n" to scan all the rows and coloms of the dmand matrix.

I figured out the problem, the dimensions of the paths array were wrong.

Thank u
Last edited on
Topic archived. No new replies allowed.