Confondu avec le char tableau lorsque le scanf

Je suis confondu avec un tout petit programme.

#include <stdio.h>

#define LEN 10

int main()
{
    char str1[LEN] = "
#include <stdio.h>
#define LEN 10
int main()
{
char str1[LEN] = "\0";
char str2[LEN] = "\0";
scanf("%s", str1);
scanf("%s", str2);
printf("%s\n", str1);
printf("%s\n", str2);
return 0;
}
"
; char str2[LEN] = "
#include <stdio.h>
#define LEN 10
int main()
{
char str1[LEN] = "\0";
char str2[LEN] = "\0";
scanf("%s", str1);
scanf("%s", str2);
printf("%s\n", str1);
printf("%s\n", str2);
return 0;
}
"
; scanf("%s", str1); scanf("%s", str2); printf("%s\n", str1); printf("%s\n", str2); return 0; }

Si mon entrée sont:

mangobatao
mangobatao123456

Pourquoi la sortie:

123456
mangobatao123456

Et non pas:

mangobatao
mangobatao123456

Comment le char tableau a été alloué dans la mémoire?

scanf("%s", str) est dangereuse en soi, sauf si vous avez le contrôle complet sur ce qui va apparaître sur stdin. Cependant gros str est, l'utilisateur peut taper plus de caractères que ne le fit en elle, ce qui provoque un comportement indéfini. (Comportement indéfini un plantage de votre programme si vous avez de la chance.)
stackoverflow.com/questions/9291348/...

OriginalL'auteur user918304 | 2011-09-01