1

i have function that takes two parameters of type LPTSTR, and i am trying print both the values using sprintf like below and i am not able to print the exact values.

int __stdcall Logon(LPTSTR UserName, LPTSTR Password)
{
  char Buffer[2048];
  sprintf(Buffer,"UserName: %s\n m_Password: %s\n",UserName,Password);
  FILE *Ls=fopen("lo.log",a);
  fprintf(Ls,Buffer);
  fclose(Ls);
}
0

2 Answers 2

4

Either fix "Use Unicode strings" in you project settings or use the

_stprintf(Buffer, _T("UserName: %S\n m_Password: %S\n"), UserName, Password);

and

#include <tchar.h>

If you use Unicode (and you do), use the '%S' format.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you for your quick response but modifying the sprintf this way is just giving me the first characters of the string not the entire string.
Please, give us the complete code (namely the LPTSTR vars definition - Buffer, UserName, Password)
2

Assuming that UserName and Password are stored as wide strings (wchar_t) and you are trying to put them into a char[] buffer, then visual c++ uses %S to accomplish this.

sprintf(Buffer,"UserName: %S\n m_Password: %S\n",UserName,Password);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.