# Problem in arrays

This is a discussion on Problem in arrays within the C Programming forums, part of the General Programming Boards category; Hi, I'm making a little software, what make and sum array or matrices (I don't know in english )... I ...

1. ## Problem in arrays

Hi,

I'm making a little software, what make and sum array or matrices (I don't know in english )... I can make the first array, is fine, but in the second array, the program copy the last row on the other rows...

and sorry my english, I'm brazilian and ... my english isnt very good ...thank you

I use DEV C++ on Win Seven

Code:
```int main(){

int i,j;
int linA,colA;
int mA[linA][colA];
int aij,mult_i,mult_j;

printf("### DETERMINANTE DE UMA MATRIZ ###\n\n\n");
//CRIANDO A MATRIZ
printf("\n### MATRIZ A ###\n\n");

printf("linhas ? "); //number of rows
scanf("%i",&linA);

printf("\n\ncolunas ? ");//number of columns
scanf("%i",&colA);

for(i=0; i<linA; i++)
{
for(j=0; j<colA; j++)
{
printf("Digite o numero da %i linha, %i coluna : (MATRIZ A): ",i,j); //first number
scanf("%i",&mA[i][j]);

}
printf("\n");
}

for(i=0; i<linA; i++)
{
for(j=0; j<colA; j++)
{
printf("%i ",mA[i][j]);
}
printf("\n");

}

//CRIANDO A SEGUNDA MATRIZ - second array
int linB,colB;
int mB[linB][colB];
i=0;
j=0;

printf("\n### MATRIZ B ###\n\n");

printf("linhas ? ");
scanf("%i",&linB);

printf("\n\ncolunas ? ");
scanf("%i",&colB);

for(i=0; i<linB; i++)
{
for(j=0; j<colB; j++)
{
printf("Digite o numero da %i linha, %i coluna : (MATRIZ B): ",i,j);
scanf("%i",&mB[i][j]);

}
printf("\n");
}

for(i=0; i<linB; i++)
{
for(j=0; j<colB; j++)
{
printf("%i ",mB[i][j]);
}
printf("\n");

}

system("pause >> log");

}```

2. Code:
```int main(){

int i,j;
int linA,colA;
int mA[linA][colA]; // at this point linA and colA contain garbage```
Kurt

3. What include files are you including? You need at least two for your program, stdio.h and stdlib.h.

Also, I doubt that your compiler supports the C99 standard so you should be using constants when you define your array size.

Jim

4. Originally Posted by jimblumberg
What include files are you including? You need at least two for your program, stdio.h and stdlib.h.

Also, I doubt that your compiler supports the C99 standard so you should be using constants when you define your array size.

Jim
Sorry, is

#include<stdio.h>#include<stdlib.h>

Tell me another compiler please =D

5. I use DEV C++ on Win Seven
Originally Posted by jimblumberg
Also, I doubt that your compiler supports the C99 standard ....
GCC supported VLA's long before C99 as an extension
Kurt

6. Originally Posted by ZuK
GCC supported VLA's long before C99 as an extension
Kurt
thanks

7. In my opinion, when learning the language you should avoid using compiler specific hacks. I suggest in this case you either use fixed array sizes, and limit your data entry to that number of elements or learn to use dynamic memory using malloc/free.

Jim

8. I agree. And I was never happy that gcc enabled its extensions by default.
Kurt

9. Don't use Dev-C++, it has a very old version of GCC

10. Originally Posted by Epy
Don't use Dev-C++, it has a very old version of GCC
Agree with Epu(metal slug i think). Go to a newer IDE

11. Originally Posted by std10093
Agree with Epu(metal slug i think). Go to a newer IDE
is that the DEV-C + + in college was recommended to be in Portuguese, but I'll look for this GCC

12. Well since you are using Windows your could also investigate Microsoft Visual C++ express edition, or Code::Blocks. Both are free and more up to date than DevC++.

Jim

13. Originally Posted by mathiasbenitez
is that the DEV-C + + in college was recommended to be in Portuguese, but I'll look for this GCC
In Greece too.But this is only for the very start of coding Netbeans,eclipse and Microsoft visual studio 2012 is what you could try...and of course what jim said