Article View: comp.lang.c.moderated
Article #2543Re: fscanf problem
From: George Swan
Date: Mon, 08 Apr 1996 16:08
Date: Mon, 08 Apr 1996 16:08
45 lines
2309 bytes
2309 bytes
In article <4jgjs2$sao@solutions.solon.com>,
<sg7248613@gamma.ntu.ac.sg> wrote:
>In article <4ja3tv$pdl@solutions.solon.com>, tanmoy@qcd.Lanl.GOV (Tanmoy Bhattacharya) writes:
>> In article <4imaao$dsi@solutions.solon.com>
>> sg7248613@omega.ntu.ac.sg writes:
>>
>> s: I have been trying to read a section of data from a file for days.
>> s: .....
>> s: Patch norm0 4 { { 0 -1 0 } { 0 -1 0 } { 0 -1 0 } { 0 -1 0 } }
>> s: Patch vert0 4 { { 0 1 0 } { 1 1 0 } { 1 1 1 } { 0 1 1 } }.
>***** edited and deleted *****
>> Please post short complete compilable examples when asking
>> questions. It is not clear to me what you mean by `I can't scanf the
>> second line successfully'. What happens? Does the program crash? Does
>> it print a message saying `I can't scanf the second line
>> successfully'?
>I am sorry that I have not made myself absolutely clear.
>What I meant was that the first line of data which goes like
> Patch norm0 4 { { 0 -1 0 } ....
>was successfully scanfed into a data structure and printed.
>The second line
> Patch vert0 4 { { 0 1 0 } ....
>encountered problems like segmentation faults or bus errors.
I haven't seen anything about the absense of the checking of return
codes in the original example and the various followups.
I'd contend that if the original poster wanted to do a scanf( ) to
read in all 28 data items, then that code should check that scanf()
returned 28. I've seen many programs were the programmers had
chosen to see whether scanf() returned EOF.
In my opinion this is dead wrong. The input might contain something
that didn't scan as a number. The program would be reading the
tokens out of synch. And some of the data elements would still
contain their values prior to initialization.
Technical Details
Message-ID:
<4kbdlc$e9c@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4imaao$dsi@solutions.solon.com> <4ja3tv$pdl@solutions.solon.com> <4jgjs2$sao@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: gswan@io.org (George Swan) Newsgroups: comp.lang.c.moderated Subject: Re: fscanf problem Date: 8 Apr 1996 11:08:11 -0500 Organization: Internex Online (shell.io.org), Toronto, Ontario, Canada Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4kbdlc$e9c@solutions.solon.com> References: <4imaao$dsi@solutions.solon.com> <4ja3tv$pdl@solutions.solon.com> <4jgjs2$sao@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com