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

int main ()
{

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

  iconv_t cd;
  size_t nstrlen, a=strlen(str), b=100;

  FILE *fp;

  cd = iconv_open("UTF-8", "LATIN1");

  nstrlen = iconv(cd, &str, &a, &loc, &b);

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

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

  fclose (fp);

}

