0
I am trying to make a program where it receives a char matrix and at the end prints the new matrix.
#include <stdio.h>
int main(){
int l,c,i,j;
scanf("%d %d",&l,&c);
char matriz[l][c],matriz_aux[l][c];
for(i = 0; i < l; i++){
for(j = 0; j < c; j++){
scanf("%s",&matriz[i][j]);
}
}
for(i = 0; i < l; i++){
for(j = 0; j < c; j++){
if(matriz[i][j] == '.'){
matriz_aux[i][j] = 'A';
}else{
matriz_aux[i][j] = matriz[i][j];
}
}
}
for(i = 0; i < l; i++){
for(j = 0; j < c; j++){
printf("%c", matriz_aux[i][j]);
}
printf("\n");
}
return 0;
}
Input example:
10 3
..#
#.#
...
.#.
.##
...
...
#..
..#
#.#
Expected output for this input:
AA#
#A#
AAA
A#A
A##
AAA
AAA
#AA
AA#
#A#
You’re reading every cell with
%s
, which apparently you wish you’d used, actually,%c
– Jefferson Quesado
Or else use
%s
to read all the line– Jefferson Quesado
Yes... With the %s the input would only close if the items were duplicated
– Vinicius Vasconcelos