I have strange behaviors when i fill a buffer...
This is the c-code(simplified)
---------------------
CODE
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char a[5];
int i;
for(i=0;i<5;i++){
a[i] = 'A';
}
printf("That's the buffer(size):%s(%i)",a,strlen(a));
return 0;
}
#include <stdlib.h>
int main(int argc, char *argv[])
{
char a[5];
int i;
for(i=0;i<5;i++){
a[i] = 'A';
}
printf("That's the buffer(size):%s(%i)",a,strlen(a));
return 0;
}
I think it's very simple code...but the output is surprising
C:\Dokumente und Einstellungen\frank-lokal\Desktop>code
That's the buffer(size):AAAAA~(6)
C:\Dokumente und Einstellungen\frank-lokal\Desktop>
6chars? Where came the '~' from?
I asked a friend because this is total wired for me ...he codes the same on openbsd with gcc same problem. The buffer is filled with a char or some chars at the end without any code for that sometimes the buffer was 10 chars bigger then declared.
Has somebody an idea what is wrong with the code?
