int MatrizNaoActiva (PtMatriz pgrupom[], int pnm)
{
if (pgrupom[pnm] == NULL)
{
printf("\e[1m\e[26;1f| A matriz %d não existe! ", pnm);
printf("\e[0m\e[27;1f| Prima uma tecla para continuar ");
scanf ("%*[^\n]"); scanf ("%*c");
return 1;
}
else return 0;
}
void LerDimensaoMatriz (unsigned int *pnl, unsigned int *pnc)
{
do
{
*pnl = 0;
printf("\e[22;1f| Nº de linhas da matriz -> ");
printf("\e[22;29f"); scanf ("%d", pnl);
scanf ("%*[^\n]"); scanf ("%*c");
} while (*pnl < 1 || *pnl > 10);
do
{
*pnc = 0;
printf("\e[22;1f| Nº de colunas da matriz -> ");
printf("\e[22;30f"); scanf ("%d", pnc);
scanf ("%*[^\n]"); scanf ("%*c");
} while (*pnc < 1 || *pnc > 10);
}
void LerNomeFicheiro (char *pnf)
{
int Status;
do
{
printf("\e[22;1f| Nome do ficheiro -> ");
printf("\e[22;23f"); Status = scanf ("%20[^\n]", pnf);
scanf ("%*[^\n]"); scanf ("%*c");
} while (Status == 0);
}
void EscreverMensagemErro (char *pmsg)
{
printf("\e[26;1f| %s de matrizes não foi efectuada devido a -> \e[1m%s", pmsg, MensagemErroMatriz ());
printf("\e[0m\e[27;1f| Prima uma tecla para continuar ");
scanf ("%*[^\n]"); scanf ("%*c");
}
PtMatriz LerMatriz (unsigned int pnl, unsigned int pnc)
{
PtMatriz Mat; unsigned int L, C; int Elemento, Status;
/* cria a matriz nula */
if ((Mat = CriarMatrizNula (pnl, pnc)) == NULL) return NULL;
/* leitura das componentes da matriz do teclado */
for (L = 0; L < pnl; L++)
{
for (C = 0; C < pnc; C++)
{
do
{
printf("\e[22;1f| Matriz[%d,%d]? ", L+1, C+1);
printf("\e[22;16f"); Status = scanf ("%d", &Elemento);
scanf ("%*[^\n]"); scanf ("%*c");
} while (Status == 0);
EscreverCompMatriz (Mat, L, C, Elemento);
}
}
return Mat; /* devolve a matriz criada */
}
void EscreverMatriz (PtMatriz pgrupom[], int pnm)
{
unsigned int L, C, NL, NC;
DimensaoMatriz (pgrupom[pnm], &NL, &NC);
printf("\e[1m");
for (L = 0; L < NL; L++)
{
printf("\e[%d;65f ", 6+L);
for (C = 0; C < NC; C++)
printf ("%4d ", LerCompMatriz (pgrupom[pnm], L, C));
}
printf("\e[0m");
}
}
void AlterarMatriz (PtMatriz pmat)
{
unsigned int L, C, NL, NC; char Car; int Elemento, Status;
DimensaoMatriz (pmat, &NL, &NC);
do
{
do
{
L = -1;
printf("\e[22;1f| Nº da linha do elemento da matriz -> ");
printf("\e[22;40f"); scanf ("%d", &L);
scanf ("%*[^\n]"); scanf ("%*c");
} while (L < 1 || L > NL);
do
{
C = -1;
printf("\e[22;1f| Nº da coluna do elemento da matriz -> ");
printf("\e[22;41f"); scanf ("%d", &C);
scanf ("%*[^\n]"); scanf ("%*c");
} while (C < 1 || C > NC);
do
{
printf("\e[22;1f| Matriz[%d,%d]? ", L, C);
printf("\e[22;16f"); Status = scanf ("%d", &Elemento);
scanf ("%*[^\n]"); scanf ("%*c");
} while (Status == 0);
EscreverCompMatriz (pmat, L-1, C-1, Elemento);
do
{
printf("\e[22;1f| Deseja alterar mais algum elemento da matriz (s/n)? ");
printf("\e[22;55f"); scanf ("%c", &Car); Car = tolower (Car);
scanf ("%*[^\n]"); scanf ("%*c");
} while (Car != 'n' && Car != 's');
} while (Car == 's');