* scanf problem on Vax C vs Dec C
@ 1997-12-17 5:00 Robert Young
1997-12-18 5:00 ` Boris Gubenko
1997-12-19 5:00 ` Ryan Moore
0 siblings, 2 replies; 6+ messages in thread
From: Robert Young @ 1997-12-17 5:00 UTC (permalink / raw)
I have code using Vax C on VMS that uses scanf. It appears to function
properly, waiting for a 'new line' character to be entered. Recompiled on
Dec C on an Alpha VMS system, scanf does not appear to wait for the new line
character. VMS is 6.1 in both cases with corresponding compatible (ie old)
compilers..
Any ideas? I am at a loss..........
Contact vyoung@groupz.net if you have an idea.......Thanks in advance
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: scanf problem on Vax C vs Dec C
1997-12-17 5:00 scanf problem on Vax C vs Dec C Robert Young
@ 1997-12-18 5:00 ` Boris Gubenko
1997-12-19 5:00 ` Ryan Moore
1997-12-19 5:00 ` Ryan Moore
1 sibling, 1 reply; 6+ messages in thread
From: Boris Gubenko @ 1997-12-18 5:00 UTC (permalink / raw)
To: Robert Young
Robert Young wrote:
>
> I have code using Vax C on VMS that uses scanf. It appears to function
> properly, waiting for a 'new line' character to be entered. Recompiled on
> Dec C on an Alpha VMS system, scanf does not appear to wait for the new line
> character. VMS is 6.1 in both cases with corresponding compatible (ie old)
> compilers..
>
> Any ideas? I am at a loss..........
>
> Contact vyoung@groupz.net if you have an idea.......Thanks in advance
The problem does not necessarily have to do with the scanf
function itself. It may relate to the changes in C RTL I/O
subsystem as well. A small sample program demonstrating
different behaviour with VAX C and DEC C would help (the
smaller, the better).
The only difference in scanf between VAX C and DEC C I'm
aware of is processing scansets. DEC C behaviour is
ANSI-compliant while VAX C is not.
--
Boris Gubenko. Digital Equipment Corp. Nashua, NH.
DEC C RTL. (603) 884-1675 boris@tle.enet.dec.com
======================================================
All the opinions voiced are mine alone and do not
reflect anyone else's opinion, including my employer's.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: scanf problem on Vax C vs Dec C
1997-12-18 5:00 ` Boris Gubenko
@ 1997-12-19 5:00 ` Ryan Moore
1997-12-19 5:00 ` Kaz Kylheku
1997-12-19 5:00 ` Chris Engebretson
0 siblings, 2 replies; 6+ messages in thread
From: Ryan Moore @ 1997-12-19 5:00 UTC (permalink / raw)
In article <3499185B.63ED5638@tle.enet.dec.com>, boris@tle.enet.dec.com says...
>
>Robert Young wrote:
>>
>> I have code using Vax C on VMS that uses scanf. It appears to function
>> properly, waiting for a 'new line' character to be entered. Recompiled on
>> Dec C on an Alpha VMS system, scanf does not appear to wait for the new line
>> character. VMS is 6.1 in both cases with corresponding compatible (ie old)
>> compilers..
>>
>> Any ideas? I am at a loss..........
>>
>> Contact vyoung@groupz.net if you have an idea.......Thanks in advance
>
> The problem does not necessarily have to do with the scanf
> function itself. It may relate to the changes in C RTL I/O
> subsystem as well. A small sample program demonstrating
> different behaviour with VAX C and DEC C would help (the
> smaller, the better).
>
> The only difference in scanf between VAX C and DEC C I'm
> aware of is processing scansets. DEC C behaviour is
> ANSI-compliant while VAX C is not.
Here's an example of a difference:
#include <stdio.h>
main()
{
char bar[50];
printf("1: ");
scanf("%s", bar);
fflush(stdin);
printf("2: ");
scanf("%c", bar);
}
On VAX C, the second scanf() will wait until the user enters a character
followed by the enter key. On DEC C, the second scanf() will *not* wait for
the user to enter a character.
VAX C v3.2-044 on VAX
DEC C V5.0-003 on Alpha
-Ryan
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: scanf problem on Vax C vs Dec C
1997-12-19 5:00 ` Ryan Moore
@ 1997-12-19 5:00 ` Kaz Kylheku
1997-12-19 5:00 ` Chris Engebretson
1 sibling, 0 replies; 6+ messages in thread
From: Kaz Kylheku @ 1997-12-19 5:00 UTC (permalink / raw)
In article <67eef5$7ei$1@thefuture.qualcomm.com>,
Ryan Moore <rmoore@qualcomm.com> wrote:
>Here's an example of a difference:
>
>#include <stdio.h>
>
>main()
>{
> char bar[50];
>
> printf("1: ");
> scanf("%s", bar);
>
> fflush(stdin);
I'm afraid that doing an output flush operation on an input stream
results in undefined behavior. Undefined behavior can easily be responsible
for one compiler behaving differently from another. Allowing fflush()
on stdin is an extension that some systems support as a non-portable
way of throwing away data that has been queued up in the input buffer.
> printf("2: ");
You should be doing fflush(stdout) to ensure that the output appears
prior to the expectation of input from the user.
> scanf("%c", bar);
>}
>
>On VAX C, the second scanf() will wait until the user enters a character
>followed by the enter key. On DEC C, the second scanf() will *not* wait for
>the user to enter a character.
The %c conversion specifier causes the next character in the input stream
to be dequeued whether or not it is a whitespace character ot what
have you. Unlike with %s, no skipping of leading whitespace occurs. So if
there is an unremoved newline character in the input stream, it is becomes
converted.
It could be that one compiler's library supports fflush(stdin) as a way
of throwing away that extra newline. Since the behavior is undefined,
a compiler may do anything it pleases, such as provide an extension,
arrange for the program to die, etc.
Try it with both compilers without the fflush(stdin) and post your results.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: scanf problem on Vax C vs Dec C
1997-12-19 5:00 ` Ryan Moore
1997-12-19 5:00 ` Kaz Kylheku
@ 1997-12-19 5:00 ` Chris Engebretson
1 sibling, 0 replies; 6+ messages in thread
From: Chris Engebretson @ 1997-12-19 5:00 UTC (permalink / raw)
In article <67eef5$7ei$1@thefuture.qualcomm.com>, rmoore@qualcomm.com (Ryan Moore) writes:
|> Here's an example of a difference:
|>
|> #include <stdio.h>
|>
|> main()
|> {
|> char bar[50];
|>
|> printf("1: ");
|> scanf("%s", bar);
|>
|> fflush(stdin);
|>
|> printf("2: ");
|> scanf("%c", bar);
|> }
|>
|> On VAX C, the second scanf() will wait until the user enters a character
|> followed by the enter key. On DEC C, the second scanf() will *not* wait for
|> the user to enter a character.
And insofar as the C programming language is concerned, the behavior
of both implementations is absolutely correct.
Regards,
--
Chris Engebretson - Raytheon STX Corporation | Ph#: (605)594-6829
USGS EROS Data Center, Sioux Falls, SD 57198 | Fax: (605)594-6940
http://edcwww.cr.usgs.gov/ mailto:engebret@sg1.cr.usgs.gov
Opinions are not those of Raytheon Systems Company or the USGS.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: scanf problem on Vax C vs Dec C
1997-12-17 5:00 scanf problem on Vax C vs Dec C Robert Young
1997-12-18 5:00 ` Boris Gubenko
@ 1997-12-19 5:00 ` Ryan Moore
1 sibling, 0 replies; 6+ messages in thread
From: Ryan Moore @ 1997-12-19 5:00 UTC (permalink / raw)
In article
<C6E5BFCFBCCA2B1B.3CA6CD5AB390B242.73B97B6D4A3E9E0D@library-proxy.airnews.net>,
rcyoung@groupz.net says...
>
>I have code using Vax C on VMS that uses scanf. It appears to function
>properly, waiting for a 'new line' character to be entered. Recompiled on
>Dec C on an Alpha VMS system, scanf does not appear to wait for the new line
>character. VMS is 6.1 in both cases with corresponding compatible (ie old)
>compilers..
>
>Any ideas? I am at a loss..........
Yeah, I had a similar experience with VAX C and DEC C acting differently on
scanf("%c", &blah). I don't remember why it acted differently.... it may have
to do with scanf("%c"...) picking up a newline from a previous scanf()
statement. I ended up changing my scanf("%c") stuff to scanf("%s") stuff and
using the first character in the resulting string.
-Ryan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~1997-12-19 5:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-12-17 5:00 scanf problem on Vax C vs Dec C Robert Young
1997-12-18 5:00 ` Boris Gubenko
1997-12-19 5:00 ` Ryan Moore
1997-12-19 5:00 ` Kaz Kylheku
1997-12-19 5:00 ` Chris Engebretson
1997-12-19 5:00 ` Ryan Moore
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox