#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
 
int main(int argc, char **argv) {
	int     index, len;
	wint_t  retval;
	FILE    *fp;
	wchar_t *pwcs;
	
	setlocale(LC_ALL, "");

	/* Error Handling if fopen was not successful. */
	if((fp = fopen("file", "w")) == NULL){
	    /*  Error handler  */
	} else {
	    /* 
	     * Let len indicate number of wide chars to output.
	     * pwcs points to a wide character buffer of BUFSIZ.
	     */
	    for (index = 0; index < len; index++){
	        retval = fputwc(*pwcs++, fp);
	        if (retval == WEOF) /* write error occurred */
	            break;
	            /* errno is set to indicate the error. */
	    }
	}
}