I know in C the last character was the null character, but I'm confused what this means?
so why do we subtract it by one?Code:if ( sz[ strlen( sz ) - 1 ] == '\\' ) // Is last character a '\'? // . . .
I know in C the last character was the null character, but I'm confused what this means?
so why do we subtract it by one?Code:if ( sz[ strlen( sz ) - 1 ] == '\\' ) // Is last character a '\'? // . . .
Arrays start at zero. If strlen is 8, and you want to access the eighth letter, what number should you put in the brackets?
Think about the smallest case possible.
A string one character long, just an X say. It will have sz[0] = 'X' and sz[1] = '\0' (null terminator).
Clearly the string length here is 1, but clearly you don't want to get sz[1].
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"