#include #include #include #include int main(void) { FILE *stream; FILE *stream_out; wchar_t wcs[100]; int compt; if (NULL == (stream = fopen("fgetws.txt", "rb"))) { system("PAUSE"); printf("Unable to open: \"fgetws.txt\"\n"); exit(1); } if (NULL == (stream_out = fopen("fgetws_out.txt", "wb"))) { system("PAUSE"); printf("Unable to open: \"fgetws_out.txt\"\n"); exit(1); } compt = 0; errno = 0; fgetwc(stream); /* pour skipper le BOM (Byte-Order Mark) FFFE */ while (1) { compt ++; if (NULL == fgetws(wcs, 100, stream)) { if (EILSEQ == errno) { printf("An invalid wide character was encountered.\n"); system("PAUSE"); fclose(stream); fclose(stream_out); exit(1); } else if (feof(stream)) { printf("End of file reached.\n"); system("PAUSE"); fclose(stream); fclose(stream_out); exit(1); } else { fclose(stream); fclose(stream_out); perror("Read error.\n"); } } printf("compt = %d\n", compt); printf("wcs = \"%ls\"\n", wcs); fprintf(stream_out, "%ls", wcs); system("PAUSE"); } return 0; } /************************************************************ Assuming the file fgetws.dat contains: This test string should not return -1 The output should be similar to: wcs = "This test string should not return -1" ************************************************************/