Hey guys,

So I today I converted my programs from VS 2005 to VS 2010.

I came across an issue involving the string null terminator ('\0') in a function of mine. (Note: It worked in VS 2005).

int StrLength(string str)
	int i = 0;

	while(str[i] != '\0')

	return i;

I get the error: 'string subscript out of range'.

My take on this is that when the index gets to the end of the string (where it should compare the null terminator) it has already jumped off the end of the string.

I'm probably wrong though.

Does anyone have any idea what to do here? Any help is appreciated.

7 Years
Discussion Span
Last Post by Narue

what happens if string is uninitialized ?

Edited by Crutoy: n/a


How do you know str ends with '\0'? Unless you placed on there explicitly, the error is correct and you're walking off the end of the string.


Ah I see. I did not place it there explicitly. I just don't understand why it works in 2005 and not 2010. Thank you for the replies.


The string is initialized and it is not empty, but thanks guys.


I just don't understand why it works in 2005 and not 2010.

Clearly there were improvements, if this bug got through on 2005 yet gets caught on 2010. :icon_rolleyes:

Edited by Narue: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.