> For the complete documentation index, see [llms.txt](https://malwaresourcecode.com/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://malwaresourcecode.com/home/markdown/wchar-to-char/wchartocharunsafe.md).

# WCharToCharUnsafe

```cpp
#include <Windows.h>

SIZE_T WCharStringToCharString(PCHAR Destination, PWCHAR Source, SIZE_T MaximumAllowed)
{
	INT Length = (INT)MaximumAllowed;

	while (--Length >= 0)
	{
#pragma warning( push )
#pragma warning( disable : 4244)
		if (!(*Destination++ = *Source++))
			return MaximumAllowed - Length - 1;
#pragma warning( pop ) 
	}

	return MaximumAllowed - Length;
}

INT main(VOID)
{
	WCHAR String1[] = L"I like cats a lot";
	CHAR String2[256] = { 0 };
	SIZE_T Length = 0;

	Length = WCharStringToCharString(String2, String1, 256);

  return ERROR_SUCCESS;
}
```
