How to find the length of an LPCSTR

Zain Rizvi picture Zain Rizvi · Oct 13, 2009 · Viewed 18.3k times · Source

I'm trying to convert an LPCSTR to an integer using atoi(), and to verify that the conversion occurred successfully I want to count the number of digits in the integer it produced and the original LPCSTR (it should contain nothing but integers)

I'm having a hard time finding a good way to calculate the length of the LPCSTR. So far the only way seems to be just counting until I get to a '/0'

Any suggestions for a better method?

Thanks

Answer

MrD picture MrD · Mar 14, 2013

To find the length (in this case, the number of digits) of an LPCTSTR, you should be using lstrlen() and not strlen(). Source: MSDN