0

I want to output some wchar_t array filled from some windows api into a file opened with fopen:

wchar_t content[256];
SomeWindowsAPI(content, 256);
FILE *file;
file=fopen( "C:\\log","a+");
fputs(content , file); //????

However, fputs expects a const char* array. Is there some other C api to write to a file pipe that expects wide array characters?

lurscher
  • 25,930
  • 29
  • 122
  • 185
  • @KerrekSB: add a link to http://msdn.microsoft.com/en-us/library/t33ya8ky%28v=vs.71%29.aspx and make that an answer... – Christoph Feb 18 '12 at 22:06

1 Answers1

1

For printing a null-terminated sequence, the wide analogue of fputs is fputws:

int fputws(const wchar_t *restrict ws, FILE *restrict stream);

As an alternative, you can write the raw data in your wide string with fwrite:

wchar_t str[] = L"Hello World";
FILE * fp = /* ... */;

fwrite(str, sizeof(wchar_t), wcslen(str), fp);
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084