0
Guys, I’m back again. I applied some changes that the members here suggested in another post, but the values are still not read correctly. Now gives up to integer values (before DOS printed negative values with more than 5 digits). Follows part of the code:
void (CPU)
{
setlocale(LC_ALL, "Portuguese");
int matriiz_A[5][5];
char matriz_A[5][5];
int matriz_B[3][2];
int matriz_C[3][2];
int m, n, k, l, i, j, x, aux;
printf("\n Abaixo temos a matriz A \n");
FILE *matrizA;
matrizA = fopen("matriz_A.txt", "r");
if (matrizA == NULL)
{
printf("\nNão foi possivel abrir o arquivo. \n");
exit(0);
}
while (fgets(matriz_A, 25, matrizA) != NULL);
{
for (m = 0; m<5; m++)
{
for (n = 0; n<5; n++)
{
fscanf(matrizA," %d%*c ", &matriz_A[m][n]);
printf(" %d ", matriz_A[m][n]);
}
printf("\n");
}
}
fclose(matrizA);
system("pause");
}
int main(int argc, char const *argv[])
{
setlocale(LC_ALL, "Portuguese");
char escolha = '0';
printf("\nEm que modo você deseja executar o programa? \n");
printf("(1) CPU \n");
printf("(2) GPU \n");
printf("Qualquer outra tecla fecha o programa \n");
escolha = getche();
if (escolha == '1')
{
CPU();
}
else if (escolha == '2')
{
}
else if ((escolha != '1') && (escolha != '2'))
{
printf("\nEscolha inválida. Programa será encerrado\n");
exit(1);
}
//system("pause");
return 0;
}
Below is the file . txt that I want to read:
01 00 02 03 04
00 05 06 00 07
08 09 00 11 12
13 00 14 15 00
00 00 16 17 18
The result I got was this:
using aux I also got the same result. Would it be a problem with the getche() function? This because I realized that in Linux it made garbage come out in the matrix, already in windows no. I researched in depth on the net and have not solved yet. :(
If the solution people presented to you in your other post didn’t solve your problem, you should have exposed it to them in the response comments.
– user142154