'sprintf': cannot convert parameter 1 from 'TCHAR *[1024]' to 'char *'
-
I am trying to enable an application for unicode. //char c_buffer[ARRAY]; TCHAR c_buffer[ARRAY]; above are the changes I made into code. Which breaks at this code in the .cpp file sprintf(c_buffer, "%d", pb->i_id); abc.cpp: error C2664: 'sprintf': cannot convert parameter 1 from 'TCHAR *[1024]' to 'char *' Why so ? I have added TCHAR.h and strsafe.h
-
I am trying to enable an application for unicode. //char c_buffer[ARRAY]; TCHAR c_buffer[ARRAY]; above are the changes I made into code. Which breaks at this code in the .cpp file sprintf(c_buffer, "%d", pb->i_id); abc.cpp: error C2664: 'sprintf': cannot convert parameter 1 from 'TCHAR *[1024]' to 'char *' Why so ? I have added TCHAR.h and strsafe.h
Use
wsprintf
-wsprintf(c_buffer, _T("%d"), pb->i_id);
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
-
I am trying to enable an application for unicode. //char c_buffer[ARRAY]; TCHAR c_buffer[ARRAY]; above are the changes I made into code. Which breaks at this code in the .cpp file sprintf(c_buffer, "%d", pb->i_id); abc.cpp: error C2664: 'sprintf': cannot convert parameter 1 from 'TCHAR *[1024]' to 'char *' Why so ? I have added TCHAR.h and strsafe.h
Quote:
sprintf(c_buffer, "%d", pb->i_id);
change to
_stprintf(c_buffer, _T("%d"), pb->i_id);
see sprintf, _sprintf_l, swprintf, _swprintf_l, __swprintf_l[^]
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite
-
Use
wsprintf
-wsprintf(c_buffer, _T("%d"), pb->i_id);
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
-
Quote:
sprintf(c_buffer, "%d", pb->i_id);
change to
_stprintf(c_buffer, _T("%d"), pb->i_id);
see sprintf, _sprintf_l, swprintf, _swprintf_l, __swprintf_l[^]
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite
However, the swprintf function, which is a VC++ library function is the correct one to use.
The wsprintf function is part of some windows API, and does not support all the formatting options. For example wsprintf does not support the "*" width specification.Thanks !
-
However, the swprintf function, which is a VC++ library function is the correct one to use.
The wsprintf function is part of some windows API, and does not support all the formatting options. For example wsprintf does not support the "*" width specification.Thanks !
If you are using
TCHAR
to define your data then you must use the routines with the_st
prefix as described in http://msdn.microsoft.com/en-us/library/ybk95axf.aspx[^]/ This allows the compiler to generate code for ASCII or Unicode depending on your project settings. If your program is only ever going to handle Unicode character data then you should useWCHAR
and thePW
prefixed pointers. -
Use
wsprintf
-wsprintf(c_buffer, _T("%d"), pb->i_id);
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
Hello superman...just trying my luck by asking this to you... problem piece of code - if(Function(parm1, parm2, parm3)==0){ error - cannot convert parameter 3 from 'char [1024]' to 'wchar_t *' Function is expecting wchar_t but its getting char[1024] from some where. I changed the function signature to accept wchar_t type in header file. objective is to make the whole code UNICODE enabled. I have added all the tchar.h, wchar.h fiels param 3 has been defined (modified) as wchar_t in all the connected files too. I cant debug yet. Pls help how can i get rid of this error. I am working in vs2010.I counter checked it about five times and gave the search in solution to find if parm3 is still 'char' somewhere else. I am seriously doubting typecasting the wchar_t parm3[] before passing it function i think. I went to function declaration and changed it to char* to wchar_t* too. I doubt that might not be straight forward. there should be some changes.
-
Hello superman...just trying my luck by asking this to you... problem piece of code - if(Function(parm1, parm2, parm3)==0){ error - cannot convert parameter 3 from 'char [1024]' to 'wchar_t *' Function is expecting wchar_t but its getting char[1024] from some where. I changed the function signature to accept wchar_t type in header file. objective is to make the whole code UNICODE enabled. I have added all the tchar.h, wchar.h fiels param 3 has been defined (modified) as wchar_t in all the connected files too. I cant debug yet. Pls help how can i get rid of this error. I am working in vs2010.I counter checked it about five times and gave the search in solution to find if parm3 is still 'char' somewhere else. I am seriously doubting typecasting the wchar_t parm3[] before passing it function i think. I went to function declaration and changed it to char* to wchar_t* too. I doubt that might not be straight forward. there should be some changes.
To support UNICODE, you need to use
wchar_t
instead ofchar
. You also need to use the string functions that work onwchar_t
likewcslen
,wcscat
etc. While defining string literals use the L prefix -L"Hello World"
If you have a string that is already encoded as ASCII, you need to convert it to UNICODE. Simply typecasting will not work. You can use the MultiByteToWideChar[^] API to do the conversion.«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)