Problems with input of arrays in C

1

I want to make a C-RAM simulator and I need to manipulate strings, so I would like to use a 4x4 array to input 4 memory locations with 4 bits: 1010 1000 1011 0000 Something like that.

#include<Stdio.h>
void main(){
char array[4][5];
printf("Informe as 4 posicoes:\n");
int i;
//leitura
for(i=0;i<4;i++){       
    scanf("%s", array[i]);
}
//impressão
printf("Imprimindo!\n");
for(i=0;i<4;i++){
    printf("%s\n", array[i]);
}

}

But the impression of this array is going to be a bit confusing. if I change array [4] [4] to array [4] [5] the print will be normal.

    
asked by anonymous 31.03.2017 / 14:35

1 answer

0

As you are working with strings, you need to create arrays with enough space to store the '\ 0' (zero backslash) delimiter.

link

    
31.03.2017 / 16:43