Problems with C arrays input

Asked

Viewed 48 times

1

I intend to make a simulator of memory ram in C and need to manipulate strings, at first I would like to use a 4x4 array for input of 4 memory positions 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]);
}

}

However the printing of this array will come out a bit confusing. if I switch from array[4][4] to array[4][5] the print will be normal.

  • What’s the matter?

  • the printing of the array is confusing, with type: 1111000033334444 000033334444 33334444

  • of which the entry was 1111 0000 3333 4444

  • I can’t play: http://ideone.com/gaHTtB

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.