sprintf_s problem
-
hi, I have a sql in my program. What I want is exactly like this:
select *
from tbl t
where t.name like '%xyz%'So in source code, I create sql like this:
CString name = "xyz";
::sprintf_s(szQuery, " select * from tbl t where t.name like '%%%s%%' ", name);Here is szQuery when I execute
select *
from tbl t
where t.name like '%x%'Just the first character is printed into szQuery. What's wrong here? what should I do?? Thank you in advance.
-
hi, I have a sql in my program. What I want is exactly like this:
select *
from tbl t
where t.name like '%xyz%'So in source code, I create sql like this:
CString name = "xyz";
::sprintf_s(szQuery, " select * from tbl t where t.name like '%%%s%%' ", name);Here is szQuery when I execute
select *
from tbl t
where t.name like '%x%'Just the first character is printed into szQuery. What's wrong here? what should I do?? Thank you in advance.
Do you have UNICODE enabled ?
Cédric Moonen Software developer
Charting control [v1.4] OpenGL game tutorial in C++ -
Do you have UNICODE enabled ?
Cédric Moonen Software developer
Charting control [v1.4] OpenGL game tutorial in C++ -
Do you have UNICODE enabled ?
Cédric Moonen Software developer
Charting control [v1.4] OpenGL game tutorial in C++ -
hi, I have a sql in my program. What I want is exactly like this:
select *
from tbl t
where t.name like '%xyz%'So in source code, I create sql like this:
CString name = "xyz";
::sprintf_s(szQuery, " select * from tbl t where t.name like '%%%s%%' ", name);Here is szQuery when I execute
select *
from tbl t
where t.name like '%x%'Just the first character is printed into szQuery. What's wrong here? what should I do?? Thank you in advance.
I think your project is a unicode project. So the CString will be holding a pointer to unicode string. So you the following options. 1. use _stprintf_s() intead of sprintf_s( in this case szQuery also need to be TCHAR* or TCHAR[] ) or 2. Use CStringA instead of CString or 3. Convert CString content to multibyte characters using WideCharToMultiByte() API. 4. Undef _UNICODE.
nave [OpenedFileFinder]
-
yes, Cedric. It's a Unicode project. In Project properties, The Character Set is "Use Unicode Character Set" is that wrong?
Then you have to specify %S instead of %s. CString will return a wide-character string since UNICODE is enabled. If you look at the format specification[^] you can see that %S tells printf that the string is a wide-char string (when used with printf alike functions).
Cédric Moonen Software developer
Charting control [v1.4] OpenGL game tutorial in C++ -
I think your project is a unicode project. So the CString will be holding a pointer to unicode string. So you the following options. 1. use _stprintf_s() intead of sprintf_s( in this case szQuery also need to be TCHAR* or TCHAR[] ) or 2. Use CStringA instead of CString or 3. Convert CString content to multibyte characters using WideCharToMultiByte() API. 4. Undef _UNICODE.
nave [OpenedFileFinder]
5. Or simply use %S instead of %s :-D
Cédric Moonen Software developer
Charting control [v1.4] OpenGL game tutorial in C++ -
5. Or simply use %S instead of %s :-D
Cédric Moonen Software developer
Charting control [v1.4] OpenGL game tutorial in C++ -
I think your project is a unicode project. So the CString will be holding a pointer to unicode string. So you the following options. 1. use _stprintf_s() intead of sprintf_s( in this case szQuery also need to be TCHAR* or TCHAR[] ) or 2. Use CStringA instead of CString or 3. Convert CString content to multibyte characters using WideCharToMultiByte() API. 4. Undef _UNICODE.
nave [OpenedFileFinder]