vendredi 27 mars 2015

C char array has different length than expected



I have a very simple code:



secret[]="abcdefgh";//this is declared in different function and is random word
int len=strlen(secret);//ofc it is 8 in this case
char word[len];
for(int a=0;a<len;a++){//expecting this will put '_' at positions 0-7
word[a]='_';
}
printf("%d %s",(int)strlen(word),word);


However, strlen(word) returns 11 and word contains "________� @", thus there is some obvious memory leak I can't see. Any idea?




Aucun commentaire:

Enregistrer un commentaire