Got it! Thanks for your advice. smile

If someone is interested here is the fixed code:

Code:
function read_and_convert()
{
	var source_handle, output_handle, index, string_size;
	source_handle = file_open_read("cleartext.txt"); 
   output_handle = file_open_append ("output.txt"); // open both files
   index = 0;
   wait (3); // wait a bit
   while (file_str_read(source_handle, data_str) != -1) // run loop till the end
	{
		string_size = str_len(data_str);
		while (index < string_size) // go through all the characters, one by one
		{
			str_cpy (temp_str, data_str);
			str_clip(temp_str, index); 
			str_trunc(temp_str, string_size - index - 1); 
			if (str_cmp(temp_str, "A") == 1) // an A?
			{
				str_cpy(log_str, "X"); //convert it into X
			}
			if (str_cmp(temp_str, "B") == 1)
			{
				str_cpy(log_str, "Y");
			}
			if (str_cmp(temp_str, "C") == 1)
			{
				str_cpy(log_str, "Z");
			}
			file_str_write(output_handle, log_str); 
			index += 1;
			wait(1);
		}
	   wait(1);
	}
	file_close(source_handle); // so let's close the file
	file_close(output_handle);
}