Problem in displaying MATRIX in C

0
Hello, I would like help with trying to solve the problem of an array of my program in C. It was created the matrix saying that it should be filled with such a character, it even works, but the last line always does not display the character that has been defined, and no matter how many rows and how many columns I put, the same thing always happens. I have read and reread all the code but I did not find anything abnormal. I thought it was overflow but because of the little knowledge I have overflow it does not occur in a CHAR variable. Sorry if I'm wrong

Follow the code blocks:

DECLARATIONS AND LIBRARIES:

#include <stdio.h>
#include<stdlib.h>
#include<conio.h>
#define COL 7
#define ROW 4
#define FALSE 0
#define TRUE 1

void inicializa(char matriz[ROW][COL]);
void mostrarPainel(char matriz[ROW][COL]);
void comprar(char matriz[ROW][COL]);
void reservar(char matriz[ROW][COL]);
void legenda();
int menuOpcao();
int colunaY();
int linhaX();

MENU SWITCH:

inicializa(matriz); //Iniciliza a matriz com valores .(Livre)

  do{
     system("cls");//Limpa a tela                
     opcao=menuOpcao();                   
     switch(opcao){
        case 1:
          system("cls");
          system("cls"); 
          mostrarPainel(matriz);//Mostra o Painel atualizado
          comprar(matriz); // Realiza a compra de uma cadeira no painel, marcando c/ um X
          break;

        case 2:
          system("cls");
          system("cls");
          mostrarPainel(matriz);
          reservar(matriz); //Realiza a reserva de uma cadeira no painel, marcando c/ um R
          break;

        case 3:
          system("cls");
          mostrarPainel(matriz);
          getch();
          break;   

        case 4:
          loopContinue = FALSE; //condicao para saída do programa
     }
  }while(loopContinue);

  getchar();    
  return 0;       
}
-----------------------------------------------------------------------------
void inicializa(char matriz[ROW][COL]){
     int i,j;
     for(i=1;i<=ROW;i++)
       for(j=1;j<=COL;j++)
          matriz[i][j] = '.';
}

void mostrarPainel(char matriz[ROW][COL]){

  int i,j;
  printf("\n\n         %c   PAINEL DE OCUPACOES   %c\n\n",16,17);
  printf("          ");

  for(i=1;i<=COL;i++)
    printf("%d     ",i);

  for(i=1;i<=ROW;i++){
     printf("\n\n     %d",i);
     for(j=1;j<=COL;j++)
       printf("   (%c)",matriz[i][j]);     
  }
  //apresenta o menu na tela
  legenda();
}        
------------------------------------------------------------------
    
asked by anonymous 09.11.2018 / 22:03

1 answer

0

In C (and in most major languages) arrays (vectors are one-dimensional arrays and arrays are multidimensional arrays as you should know) have indices ranging from 0 (zero) to n-1 (where n is the size of the array, that is, your array has the indexes in a similar way, so when you make your for to go through the array you would have to go from 0 to COLS / ROWS -1, you could simply do this:

void mostrarPainel(char matriz[ROW][COL]){

int i,j;
printf("\n\n %c PAINEL DE OCUPACOES %c\n\n",16,17);
printf(" ");

for(i=0;i<COL;i++){
    printf("%d ",i);
}

for(i=0;i<ROW;i++) {
    printf("\n\n %d",i); 
    for(j=1;j<=COL;j++) {
         printf(" (%c)",matriz[i][j]);
    }
} //apresenta o menu na tela legenda();
}
    
09.11.2018 / 22:14