[comp.lang.c] ungetc/scanf independent?

cspw.rures@p0.f4.n494.z5.fidonet.org (cspw rures) (03/26/90)

 
I have a VAX problem when interleaving calls to getc and ungetc with
calls to scanf.   On all the compilers I tested (except the VAX VMS 4.2),
and "ungetc" character is available to a subsequent scanf.  On the VAX
it appears that getc and ungetc have their own private "view" of the file,
not shared by scanf.
 
Is the VAX C compiler broken?   What does ANSI say?
 
     #include <stdio.h>
 
     int main(void)
     {  char c; int i;
        c = getc(stdin);
        ungetc(c,stdin);
        scanf("%d",&i);
        printf("%d\n",i);
     }
 
For test data like
123
the VAX prints 23.
 
Thanks
Pete Wentworth



--  
uucp: uunet!m2xenix!puddle!5!494!4.0!cspw.rures
Internet: cspw.rures@p0.f4.n494.z5.fidonet.org

scjones@sdrc.UUCP (Larry Jones) (03/29/90)

In article <3009.260C8D7C@puddle.fidonet.org>, cspw.rures@p0.f4.n494.z5.fidonet.org (cspw rures) writes:
> I have a VAX problem when interleaving calls to getc and ungetc with
> calls to scanf.   On all the compilers I tested (except the VAX VMS 4.2),
> and "ungetc" character is available to a subsequent scanf.  On the VAX
> it appears that getc and ungetc have their own private "view" of the file,
> not shared by scanf.
>  
> Is the VAX C compiler broken?   What does ANSI say?

The ANSI standard says that all I/O is done "as if" by calls to
getc and putc.  Thus, if you ungetc a character, it is available
to scanf.

Is the Vax C compiler broken?  Maybe, but that's irrelevant.  The
Vax C Run Time Library definitely is in VMS V4.2!  Since the
library comes with VMS, not with the compiler, and VMS is now up
to V5.3 or so, you're a little behind the times.  I suggest
updating ASAP.
----
Larry Jones                         UUCP: uunet!sdrc!scjones
SDRC                                      scjones@SDRC.UU.NET
2000 Eastman Dr.                    BIX:  ltl
Milford, OH  45150-2789             AT&T: (513) 576-2070
"You know how Einstein got bad grades as a kid?  Well MINE are even WORSE!"
-Calvin