Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Warning C4477 'sprintf' : format string '%s' requires an argument of type 'char *', but variadic argument 2 has type 'CString'

What I have tried:

sprintf(m_Tip.szUnit, "%s", "for Relay Address");
Posted
Updated 14-Nov-18 1:19am
Comments
MadMyche 14-Nov-18 7:12am    
Please provide the relevant code; the line throwing the error as well as the definitions of the variables used within that line

 
Share this answer
 
Comments
CHill60 14-Nov-18 7:21am    
5'd - didn't see your solution (nor CPallini's) until after I posted
Quote:
sprintf(m_Tip.szUnit, "%s", "for Relay Address");
"for Relay Address" doesn't look a CString to me. Possibly you are reporting the wrong line.

By the way, what is wrong with
C
m_Tip.szUnit = "for Relay Address";
?
 
Share this answer
 
Comments
Richard MacCutchan 14-Nov-18 9:50am    
Maybe it needs strcpy.
CPallini 14-Nov-18 12:23pm    
I guess m_Tip.szUnit is a CString. A wild guess, I know.
Richard MacCutchan 14-Nov-18 12:30pm    
The error message appears to be complaining about the string constant, which is a bit strange.
CPallini 14-Nov-18 12:38pm    
It is massively strange. As matter of fact, I believe the OP didn't report exactly the offending line.
Richard MacCutchan 14-Nov-18 12:40pm    
No surprise there. :(
Try using a char array for your text e.g.
C++
char s[] = "for Relay Address";
sprintf(m_Tip.szUnit, "%s", s);
Or in this case
C++
m_Tip.szUnit = "for Relay Address";
assuming m_Tip.szUnit is defined as std::string
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900