#include <stdio.h>
#include <locale.h>
#include <string.h>
#include <wchar.h>

int main ()
{

  char *str="Uma frase com acentos avião caçador melões até já",
       *loc,
       nstr[100];
  mbstate_t ps;
  size_t nstrlen;

  FILE *fp;

  memset (&ps, '\0', sizeof (ps));

  //  loc = setlocale(LC_ALL, "pt_BR.UTF-8");

  nstrlen = wcsrtombs(nstr, (const wchar_t **) &str, strlen(str), &ps);

  fp = fopen("teste.txt", "w");

  fprintf (fp, "%s: %s\n", loc, nstr);
  fputs(nstr, fp);

  fclose (fp);

}

