www.digitalmars.com         C & C++   DMDScript  

c++.stlsoft - 98/msdos/dmc EOF behavior

reply Howard <hlenderk bcpl.net> writes:
Hello this is my first post to any "newsgroup".
I apologize in advance for any misteps.

I have been learning C using the book "The C Primer" (Hancock, Kreiger, Zamir)
and dmc on a p2 running 98 and dmc in a msdos terminal for the past few months. 
  I occasionally boot to Redhat9 and use gcc but usually in 98 and compiling 
with dmc so I'm not to far from work stuff.

I have had odd problems on several occasions with stdin, not working as
expected 
in codes.  Seems like getchar, putchar, scanf, printf would leave a things like 
\n in stdin so I would have to come up with work-arounds.  I am now up to fopen 
etc. and once again am having a similar problem, this time with EOF, which 
prompts this post.  As yet I haven't found an explanation as to why or what I 
SHOULD be doing.

Here is an example of what I wound up doing this time.  Any thoughts?
Thanks, Howard
-----
#include <stdio.h>
int main()
{
printf("           primer- test17_4.c \nReading, manipulating and writing to
and 
from files \n  -using putw() and getw() \n\n");

FILE *file;
int i;

file = fopen("temp", "w");
for(i=0; i < 985; i += 123)
   { putw(i, file); }
fclose(file);

file = fopen("temp", "r");
/* while((i = getw(file)) != EOF)        DOESN'T work, loop runs on */
while((i = getw(file)) != 0xffff)     /* this catches whatever it is */
   { printf("%6d  %4x \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
            primer- test17_4.c
Reading, manipulating and writing to and from files
   -using putw() and getw()
      0     0
    123    7b
    246    f6
    369   171
    492   1ec
    615   267
    738   2e2
    861   35d
    984   3d8
----- END -----
Feb 02 2007
parent reply Matthew Wilson <no.one.no.where no.thing.com> writes:
Howard

Unfortunately you catch at my busiest time in years, so I simply won't get a
chance to help you for at least a week. Perhaps others on the group will.

FYI: From what I could glean, I think your post is OT for this group. You may
want to post to the C++ group, or maybe even try
comp.lang.c++.moderated/comp.lang.c++, which you can get to from
http://groups.google.com.

Good luck. Feel free to post again in a week's time, if you get nowhere
elsewhere.

Matthew
Feb 02 2007
parent reply Howard <hlenderk bcpl.net> writes:
Matthew Wilson wrote:
 Howard
 I think your post is OT for this group. You may want to post to the C++ group,
or maybe even try comp.lang.c++.moderated/comp.lang.c++, which you can get to
from http://groups.google.com.
 Matthew
 

another forum. I will check into your other suggested lists. sorry... Thanks, Howard
Feb 02 2007
parent "Matthew Wilson" <matthew hat.stlsoft.dot.org> writes:
 I will check into your other suggested lists.  sorry...

Not necessary. :-) Good luck
Feb 03 2007