#include #include #include #include int main(void) { FILE *stream; wchar_t wcs[100]; int compt; int *lect_ligne; if (NULL == (stream = fopen("fgetws.txt", "r"))) { system("PAUSE"); printf("Unable to open: \"fgetws.txt\"\n"); exit(1); } compt = 0; errno = 0; while (1) { lect_ligne = fgetws(wcs, 100, stream); compt ++; if (NULL == lect_ligne) { if (EILSEQ == errno) { printf("An invalid wide character was encountered.\n"); system("PAUSE"); exit(1); } else if (feof(stream)) { printf("End of file reached.\n"); system("PAUSE"); exit(1); } else { perror("Read error.\n"); } } printf("compt = %d\n", compt); printf("wcs = \"%ls\"\n", wcs); system("PAUSE"); } fclose(stream); 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" ************************************************************/