How can I delete the last character of a wchar_t* and resize accordingly? For example, having the string "test" and bringing it down to "tes"
+7
A:
How about str[wcslen(str) - 1] = '\0'
Make sure the string is at least 1 character long first though!
Rob
2009-12-06 18:02:57
Or you can be completely pedantic and write `L'\0'`.
Frank Krueger
2009-12-06 18:14:49
Or 0 - the literal has type `int` instead of `char` or `wchar_t`, but it converts to the same value.
Steve Jessop
2009-12-06 23:12:33
A:
Would you please explain what you mean by "resize accordingly"? Do you want to resize the buffer that was allocated? (Even if you think you do, you probably don't, because resizing to shave one character will probably throw the memory allocator off, but I think I should ask anyway)
Roie Marianer
2009-12-07 00:17:15