#include #include #include #include int main(void) { FILE *stream, *stream_out, *stream_verif; wchar_t wcs[100], bom, c; int compt; alpha(); printf("Fonction alpha terminee.\n"); system("PAUSE"); if (NULL == (stream = fopen("fgetws.txt", "rb"))) { printf("Unable to open: \"fgetws.txt\"\n"); system("PAUSE"); exit(1); } if (NULL == (stream_out = fopen("fgetws_out.txt", "wb"))) { printf("Unable to open: \"fgetws_out.txt\"\n"); system("PAUSE"); exit(1); } compt = 0; errno = 0; bom = fgetwc(stream); /* pour skipper le BOM (Byte-Order Mark) FFFE */ fwrite(&bom, sizeof(bom), 1, stream_out); /*écriture du BOM dans le fichier de sortie */ while (1) { compt ++; if (NULL == fgetws(wcs, 100, stream)) { if (EILSEQ == errno) { fclose(stream); fclose(stream_out); printf("An invalid wide character was encountered.\n"); system("PAUSE"); exit(1); } else if (feof(stream)) { fclose(stream); fclose(stream_out); printf("End of file reached.\n"); system("PAUSE"); exit(1); } else { fclose(stream); fclose(stream_out); perror("Read error.\n"); } } printf("compt = %d\n", compt); fwrite(wcs, wcslen(wcs)*sizeof(wchar_t), 1, stdout); fwrite(wcs, wcslen(wcs)*sizeof(wchar_t), 1, stream_out); system("PAUSE"); } return 0; } int alpha (void) { FILE *stream_verif, *stream; wchar_t bom, c; /* l'écriture du bom en dur ne fonctionne d'aucune des deux manieres suivantes: */ /* 1e manière: rien d'autre n'est écrit dans le fichier après le bom */ /* bom = L'\U0000FFFE'; */ /* 2e manière: tout ce qui doit être écrit dans le fichier après est correctement écrit, mais il y a un caractère de trop tout au début, comme si le bom avait été doublé en taille */ /* bom = L"\U0000FFFE"; */ /* recuperation du bom */ if (NULL == (stream = fopen("fgetws.txt", "rb"))) { printf("Unable to open: \"fgetws.txt\"\n"); system("PAUSE"); exit(1); } bom = fgetwc(stream); /* pour skipper le BOM (Byte-Order Mark) FFFE */ fclose(stream); /* création fichier contenant les caracteres unicode cyrilliques */ if (NULL == (stream_verif = fopen("verif.txt", "wb"))) { printf("Unable to open: \"verif.txt\"\n"); system("PAUSE"); exit(1); } fwrite(&bom, sizeof(bom), 1, stream_verif); /*écriture du BOM dans fichier de sortie */ /* la ligne qui suit ne fonctionne pas */ /* fwprintf (stream_verif, &bom); */ /* fputwc (&bom, stream_verif); */ c = L'\U00000410'; fwprintf (stream_verif, L"%c", c); c = L'\U00000411'; fwprintf (stream_verif, L"%c", c); c = L'\U00000412'; fwprintf (stream_verif, L"%c", c); fclose(stream_verif); return 0; }