why a= new char [210]; but strlen(a)= 224??


1
2
3
4
5
6
7
        char *bin;
        bin = new char [210];
	if(strlen(bin)!=210)
	{
//I used debug to detect the strlen(bin),it's 224. Not 210
		MessageBox (NULL,L"error!!",L"error!!",NULL);
	};


Why is that?

in debuger..the value of bin is
1
2
3
ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍýýýý««««««««îþ

there's really something wrong with that..
Last edited on
because strlen() is looking for the terminating 0 while the content of bin is uninitialized. The result is undefined
i think you are lucky, 'cause when i try to do something similar i get an access violation runtime error.
if you're sure you don't want to initialize the array, try this:
1
2
3
char *a;
a = new char[210];
a[209] = '\0';
Well, I see...Thanks you guys..
Topic archived. No new replies allowed.