Originally Posted By: Benni003
Hi Talemon,

just go to this post: Unicode text to string

Hey there, I'm talking about writing unicode strings to a file, not reading. I'm juggling with unicode strings now, it's just that I'm having trouble writing them.

Aynways, I wrote some utility functions to do the job, in case anyone needs:

Code:
function U_file_str_write(FILE* arg_fp, STRING* arg_str)
{
	if(U_Assert(arg_fp, "U_file_str_write: arg_fp") != 0) return;
	if(U_Assert(arg_str, "U_file_str_write: arg_str") != 0) return;
	int i;
	for(i = 0; i < str_len(arg_str) * 2; i++)
	{
		var ch = (arg_str->chars)[i];
		file_asc_write(arg_fp, ch);
	}
}

function U_file_str_writeline(FILE* arg_fp, STRING* arg_str)
{
	if(U_Assert(arg_fp, "U_file_str_write: arg_fp") != 0) return;
	U_file_str_write(arg_fp, arg_str);
	file_asc_write(arg_fp, 0x0a); // \n first byte
	file_asc_write(arg_fp, 0x00); // \n second byte
}

function U_file_str_writebom(FILE* arg_fp)
{
	if(U_Assert(arg_fp, "U_file_str_writebom: arg_fp") != 0) return;
	file_asc_write(arg_fp, 0xff); \\ 
	file_asc_write(arg_fp, 0xfe); \\ Byte-order mark(BOM) for UCS-2 LE
}

FILE* U_file_create_write(char* arg_filename)
{
	FILE* fp = file_open_write(arg_filename);
	U_file_str_writebom(fp);
	return fp;
}