I think what you wanted was this:
#include <stdio.h>
#include <stdlib.h>
int main() {
char i, j, m[3][3];
char tecla;
//captura os elementos
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("Elemento[%d][%d] = ", i, j);
tecla = getche();
scanf("%c", &m[i][j]);
}
}
//EXIBIR VALORES ORIGINAIS
printf("\n::: Valores Originais :::\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%c ", m[i][j]);
}
printf("\n");
}
tecla = getche();
}
Always use {
and }
to avoid making mistakes. For example, in this code you posted:
//EXIBIR VALORES ORIGINAIS
printf("\n::: Valores Originais :::\n");
for(i=0;i<3;i++){
for(j=0;j<3;j++)
printf("%c ",m[i][j]);
tecla[0] = getche();
printf("\n");
}
Notice that the for
inside does not have {
. This causes tecla[0] = getche();
and printf("\n");
to be outside the for
internal. If you always use {
on all for
ties, you will not have this problem. Idling everything properly will also help you a lot.
In addition, char tecla[0];
declares an array of zero positions and you write in the first position of it (position 0), which is already outside the array. This does not make sense, it is easiest to use only a common variable char tecla;
.