It's funny that it didnโt reach me today. I could have sworn I used a function in the past. But anyway, here is a solution that works and is safe, like your arguments and format string:
template < size_t _NumArgs >
int VSSCANF_S (LPCTSTR strSrc, LPCTSTR ptcFmt, INT_PTR (& arr) [_ NumArgs]) {
class vaArgs { vaArgs() {} INT_PTR* m_args[_NumArgs]; public: vaArgs(INT_PTR (&arr)[_NumArgs]) { for(size_t nIndex=0;nIndex<_NumArgs;++nIndex) m_args[nIndex] = &arr[nIndex]; } }; return sscanf_s(strSrc, ptcFmt, vaArgs(arr)); }
//////////////////////////////////////////////////// ///////////////////////////
int _tmain (int, LPCTSTR argv [])
{ INT_PTR args[3]; int nScanned = VSSCANF_S(_T("-52 Hello 456 @"), _T("%d Hello %u %c"), args); return printf(_T("Arg1 = %d, arg2 = %u, arg3 = %c\n"), args[0], args[1], args[2]); }
code>
Of:
Arg1 = -52, arg2 = 456, arg3 = @ Press any key to continue.,
Well, I canโt format it correctly, but you get the point.
source share