-3

I get this error:

argument of type "char *" is incompatible with parameter of type "LPCWSTR"

Here's a part of my code

void score(void)
{
    char s[128];
    sprintf_s(s, "Thread War! Hits:%d  Misses:%d", hit, miss);
    SetConsoleTitle(s);
    ...
}

How to fix this?

crashmstr
  • 28,043
  • 9
  • 61
  • 79
music_junkie
  • 189
  • 2
  • 16
  • I would guess that your compiler settings are set to Unicode, so the winapi functions will be unicode versions taking wide characters. [SetConsoleTitle](https://msdn.microsoft.com/en-us/library/windows/desktop/ms686050(v=vs.85).aspx) – crashmstr Nov 13 '15 at 18:21
  • The `W` in `LPCWSTR` indicates the function actually wants a `wchar_t*` instead of a `char*`. Hungarian type notation is ugly, but well clear at least if used consistently. – πάντα ῥεῖ Nov 13 '15 at 18:22
  • I understand that he wants a `wchar_t*` instead of `char*`, but if i write `wchar_t s[128]` I'll get the error with `sprintf_s` – music_junkie Nov 13 '15 at 18:27
  • 1
    @Mockingbird That is why there is `swprintf` – NathanOliver Nov 13 '15 at 18:28

1 Answers1

0

You're building with the UNICODE macro defined, which means that all functions default to their wide-character equivalent. So when you call SetConsoleTitle that's really a macro that expands to SetConsoleTitleW.

A wide character has the type wchar_t and is incompatible with char.

You either have to explicitly call SetConsoleTitleA, remove the definition of UNICODE, or start using TCHAR and related types and macros.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621