Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
c++ - 98/msdos/dmc EOF behavior
/* Hello, I am fairly new to C and am using dmc on win98/msdos terminal. I have been learning C using the book "The C Primer" (Hancock, Kreiger, Zamir) I am having trouble understanding why EOF does not work in a condition check as the book assumes it will and wonder what is causing the failure: 98/dos, dmc, my computer ?? I have come up with a work around but still the question nags. Here is the program from the book I'm trying: ----- */ #include <stdio.h> int main() { FILE *file; int i; printf("%d %x \n",EOF, EOF); /* hmmm, EOF prints ffff ffff */ file = fopen("temp", "w"); for(i=0; i < 985; i += 123) { putw(i, file); } /* with nothing: last output 03d8 ffff*/ fclose(file); file = fopen("temp", "r"); // while((i = getw(file)) != EOF) //DOESN'T work, loop always runs on */ while((i = getw(file)) != 0xffff) /* this does catch it */ { printf("%6d %4x hi-0 \n", i, i); } fclose(file); } /* ===== output ====== D:\C\primer\17_file_io> dmc -A -r -wx 17_4.c link 17_4,,,user32+kernel32/noi; D:\C\primer\17_file_io> 17_4 D:\C\primer\17_file_io> dmc -A -r -wx 17_4x1.c link 17_4x1,,,user32+kernel32/noi; D:\C\primer\17_file_io> 17_4x1 -1 ffffffff 0 0 hi-0 123 7b hi-0 246 f6 hi-0 369 171 hi-0 492 1ec hi-0 615 267 hi-0 738 2e2 hi-0 861 35d hi-0 984 3d8 hi-0 -when loop runs on the output continues with: 65535 ffff ...which repeats but ((i = getw(file)) != EOF) doesn't see it right. -I've tried != (int)EOF -no success I'm also into feof section of the book which is working, but I still wonder... Any ideas? */ Feb 03 2007
Howard skrev:/* Hello, I am fairly new to C and am using dmc on win98/msdos terminal. I have been learning C using the book "The C Primer" (Hancock, Kreiger, Zamir) I am having trouble understanding why EOF does not work in a condition check as the book assumes it will and wonder what is causing the failure: 98/dos, dmc, my computer ?? I have come up with a work around but still the question nags. Here is the program from the book I'm trying: ----- */ #include <stdio.h> int main() { FILE *file; int i; printf("%d %x \n",EOF, EOF); /* hmmm, EOF prints ffff ffff */ file = fopen("temp", "w"); for(i=0; i < 985; i += 123) { putw(i, file); } /* with nothing: last output 03d8 ffff*/ fclose(file); file = fopen("temp", "r"); // while((i = getw(file)) != EOF) //DOESN'T work, loop always runs on */ while((i = getw(file)) != 0xffff) /* this does catch it */ { printf("%6d %4x hi-0 \n", i, i); } fclose(file); } /* ===== output ====== D:\C\primer\17_file_io> dmc -A -r -wx 17_4.c link 17_4,,,user32+kernel32/noi; D:\C\primer\17_file_io> 17_4 D:\C\primer\17_file_io> dmc -A -r -wx 17_4x1.c link 17_4x1,,,user32+kernel32/noi; D:\C\primer\17_file_io> 17_4x1 -1 ffffffff 0 0 hi-0 123 7b hi-0 246 f6 hi-0 369 171 hi-0 492 1ec hi-0 615 267 hi-0 738 2e2 hi-0 861 35d hi-0 984 3d8 hi-0 -when loop runs on the output continues with: 65535 ffff ...which repeats but ((i = getw(file)) != EOF) doesn't see it right. -I've tried != (int)EOF -no success I'm also into feof section of the book which is working, but I still wonder... Any ideas? Feb 03 2007
Bertel Brander wrote:Howard skrev:/* Hello, I am fairly new to C and am using dmc on win98/msdos terminal. I have been learning C using the book "The C Primer" (Hancock, Kreiger, Zamir) I am having trouble understanding why EOF does not work in a condition check as the book assumes it will and wonder what is causing the failure: 98/dos, dmc, my computer ?? I have come up with a work around but still the question nags. Here is the program from the book I'm trying: ----- */ #include <stdio.h> int main() { FILE *file; int i; printf("%d %x \n",EOF, EOF); /* hmmm, EOF prints ffff ffff */ file = fopen("temp", "w"); for(i=0; i < 985; i += 123) { putw(i, file); } /* with nothing: last output 03d8 ffff*/ fclose(file); file = fopen("temp", "r"); // while((i = getw(file)) != EOF) //DOESN'T work, loop always runs on */ while((i = getw(file)) != 0xffff) /* this does catch it */ { printf("%6d %4x hi-0 \n", i, i); } fclose(file); } /* ===== output ====== D:\C\primer\17_file_io> dmc -A -r -wx 17_4.c link 17_4,,,user32+kernel32/noi; D:\C\primer\17_file_io> 17_4 D:\C\primer\17_file_io> dmc -A -r -wx 17_4x1.c link 17_4x1,,,user32+kernel32/noi; D:\C\primer\17_file_io> 17_4x1 -1 ffffffff 0 0 hi-0 123 7b hi-0 246 f6 hi-0 369 171 hi-0 492 1ec hi-0 615 267 hi-0 738 2e2 hi-0 861 35d hi-0 984 3d8 hi-0 -when loop runs on the output continues with: 65535 ffff ...which repeats but ((i = getw(file)) != EOF) doesn't see it right. -I've tried != (int)EOF -no success I'm also into feof section of the book which is working, but I still wonder... Any ideas? Feb 07 2007
Howard skrev:Why doesn't EOF look for all three types? ff ffff ffffffff Feb 07 2007
Bertel Brander wrote:Howard skrev:Why doesn't EOF look for all three types? ff ffff ffffffff Feb 08 2007
|