int main()
{
char btext[20];
for(int i=0; i< sizeof(btext); i++)
{
btext[i]= 'x' ;
}
for(int i=0; i< sizeof(btext); i++)
{
printf("%c", btext[i]);
}
printf("\nbtext: %s\n", btext);
return 0;
}
This gives the output:
xxxxxxxxxxxxxxxxxxxx
btext: xxxxxxxxxxxxxxxxxxxx?
Where does that ? come from? And even worse:
int main()
{
char text[] = "some text";
char btext[20];
printf("text: %s\n", text);
for(int i=0; i< sizeof(btext); i++)
{
btext[i]= 'x' ;
}
for(int i=0; i< sizeof(btext); i++)
{
printf("%c", btext[i]);
}
printf("\nbtext: %s\n", btext);
return 0;
}
This gives the output:
text: some text xxxxxxxxxxxxxxxxxxxx
btext: xxxxxxxxxxxxxxxxxxxxsome text
This drives me crazy. The code is so straightforward, but I can't figure it out. Is it a bug in the IDE? Has anyone seen something like this?