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 the {
and the }
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");
}
Note that the for
from within has not the {
. This makes the tecla[0] = getche();
and the printf("\n");
are out of the for
internal. If you always use the {
in all ties for
, you won’t have this problem. Ideating everything properly will also help you a lot.
Moreover, char tecla[0];
declares an array of zero positions and you write at its first position (position 0), which is already outside the array. This doesn’t make sense, it’s easier to use just a common variable char tecla;
.
Are you sure you want to create a zero-size vector?
– Jefferson Quesado
Watch the
{
and}
of these tiesfor
. Seems to be wrong.– Victor Stafusa
I wanted the typed letters to be displayed at the end, and that doesn’t happen, even with the change suggested by you
– Laurie Miranda
My code only shows the last letter typed
– Laurie Miranda
@Williamhenrique Do not "correct" the identation of questions where identation problems are part of the question problem!
– Victor Stafusa
@Victorstafusa blz mano! thanks for the touch!
– William Henrique