From: fredex AT fcshome DOT stoneham DOT ma DOT us Message-Id: <199605271815.OAA07597@fcshome.stoneham.ma.us> Subject: Re: djgpp 2.0 fscanf bug?? To: djgpp AT delorie DOT com Date: Mon, 27 May 1996 14:15:24 -0400 (EDT) Content-Type: text Content-Length: 6265 Thinking furiously, fredex wrote: From fredex Mon May 27 14:12:16 1996 Subject: Re: djgpp 2.0 fscanf bug?? To: j DOT aldrich6 AT genie DOT com Date: Mon, 27 May 1996 14:12:16 -0400 (EDT) In-Reply-To: <199605270553 DOT AA269296409 AT relay1 DOT geis DOT com> from "j DOT aldrich6 AT genie DOT com" at May 27, 96 05:33:00 am X-Mailer: ELM [version 2.4 PL25] Content-Type: text Content-Length: 5900 Thinking furiously, j DOT aldrich6 AT genie DOT com wrote: > Reply to message 4146431 from FREDEX AT FCSHOM on 05/26/96 7:58AM > >That's exactly my point (perhaps I didn't explain it well enough)-- on > >DJGPP's fscanf it DOESN'T return zero, and DOESN'T exit the loop. This > >code is written with the > >expectation that when fscanf tries to convert that MSH it'll fail > >because it's not an integer, then return zero so the inner loop will be > >exited. But on DJGPP it returns 4. > > Velly odd. Can you post an exact copy of the output you get from the > program? (along with your input data, too - I have limited short-term > memory. :) It sounds to me like there's some subtle bug there but I > can't be sure w/o seeing it. > OK, here's further detail on this one. Below, once again, is the short sample program that illustrates the problem, followed by two sets of output. The first output is from my Linux system, and the second is from DJGPP 2.0 on DOS 6.2, both preceded by the first few lines of the input data. You'll note that in the first set (i.e., from Linux) the program terminates when it hits the line that contains only "MSH". This line should cause fscanf to return 0, since the first token it tried to parse did not match the format string (i.e., "%d%s%s%s"), being a string rather than an integer. The output from the DJGPP program is different, you'll note that it did not return 0 for that line, and that furthermore it returned incorrect conversions. Don't worry about the 'pos' value being different--that's because of the differences in text files between DOS and Linux/Unix. Fred ------------------------------ The Program------------------------------------ #include main (int argc, char ** argv) { char segTypes[256], typ[10], ro[10], nr[20]; int sto = 0, fldLen, n = 0; FILE * infile; if (argc != 2) { fprintf (stderr, "args!\n"); exit (0); } infile = fopen (argv[1], "r"); if (infile == (FILE *)0) { fprintf (stderr, "oops!\n"); exit (0); } while ((n = fscanf (infile, "%d%s%s%s", &fldLen, typ, ro, nr)) > 0) { fgets (segTypes, sizeof (segTypes), infile); /* suck in the comment */ printf ("n=%d, fldLen=%d, typ=%s, ro=%s, nr=%s, pos=%ld\n", n, fldLen, typ, ro, nr, ftell (infile)); } printf ("n=%d, lastpos=%ld\n", n, ftell (infile)); fclose (infile); } ------------------------------ The Sample Data------------------------------- 1 ST REQ NO_RPT /* 1 Field Separator */ 4 ST REQ NO_RPT /* 2 Encoding Characters */ 15 ST OPT NO_RPT /* 3 Sending Application */ 20 ST OPT NO_RPT /* 4 Sending Facility */ 15 ST OPT NO_RPT /* 5 Receiving Application */ 30 ST OPT NO_RPT /* 6 Receiving Facility */ 19 TS OPT NO_RPT /* 7 Date/Time of Message */ 40 ST OPT NO_RPT /* 8 Security */ 7 ID REQ NO_RPT /* 9 Message Type */ 20 ST REQ NO_RPT /* 10 Message Control ID */ 1 ID REQ NO_RPT /* 11 Processing ID */ 8 NM REQ NO_RPT /* 12 Version ID */ 15 NM OPT NO_RPT /* 13 Sequence Number */ 180 ST OPT NO_RPT /* 14 Continuation Pointer */ MSH 2 ID REQ NO_RPT /* 1 Acknowledgement Code */ 20 ST REQ NO_RPT /* 2 Message Control ID */ 80 ST OPT NO_RPT /* 3 Text Message */ 15 NM OPT NO_RPT /* 4 Expected Sequence Number */ 1 ID OPT NO_RPT /* 5 Delayed Ack Type */ MSA ---------------------------- The Linux output -------------------------------- n=4, fldLen=1, typ=ST, ro=REQ, nr=NO_RPT, pos=52 n=4, fldLen=4, typ=ST, ro=REQ, nr=NO_RPT, pos=104 n=4, fldLen=15, typ=ST, ro=OPT, nr=NO_RPT, pos=157 n=4, fldLen=20, typ=ST, ro=OPT, nr=NO_RPT, pos=210 n=4, fldLen=15, typ=ST, ro=OPT, nr=NO_RPT, pos=263 n=4, fldLen=30, typ=ST, ro=OPT, nr=NO_RPT, pos=317 n=4, fldLen=19, typ=TS, ro=OPT, nr=NO_RPT, pos=371 n=4, fldLen=40, typ=ST, ro=OPT, nr=NO_RPT, pos=425 n=4, fldLen=7, typ=ID, ro=REQ, nr=NO_RPT, pos=479 n=4, fldLen=20, typ=ST, ro=REQ, nr=NO_RPT, pos=533 n=4, fldLen=1, typ=ID, ro=REQ, nr=NO_RPT, pos=587 n=4, fldLen=8, typ=NM, ro=REQ, nr=NO_RPT, pos=641 n=4, fldLen=15, typ=NM, ro=OPT, nr=NO_RPT, pos=696 n=4, fldLen=180, typ=ST, ro=OPT, nr=NO_RPT, pos=751 lastpos=751 ----------------------------- The DJGPP output-------------------------------- n=4, fldLen=1, typ=ST, ro=REQ, nr=NO_RPT, pos=53 n=4, fldLen=4, typ=ST, ro=REQ, nr=NO_RPT, pos=106 n=4, fldLen=15, typ=ST, ro=OPT, nr=NO_RPT, pos=160 n=4, fldLen=20, typ=ST, ro=OPT, nr=NO_RPT, pos=214 n=4, fldLen=15, typ=ST, ro=OPT, nr=NO_RPT, pos=268 n=4, fldLen=30, typ=ST, ro=OPT, nr=NO_RPT, pos=323 n=4, fldLen=19, typ=TS, ro=OPT, nr=NO_RPT, pos=378 n=4, fldLen=40, typ=ST, ro=OPT, nr=NO_RPT, pos=433 n=4, fldLen=7, typ=ID, ro=REQ, nr=NO_RPT, pos=488 n=4, fldLen=20, typ=ST, ro=REQ, nr=NO_RPT, pos=543 n=4, fldLen=1, typ=ID, ro=REQ, nr=NO_RPT, pos=598 n=4, fldLen=8, typ=NM, ro=REQ, nr=NO_RPT, pos=653 n=4, fldLen=15, typ=NM, ro=OPT, nr=NO_RPT, pos=709 n=4, fldLen=180, typ=ST, ro=OPT, nr=NO_RPT, pos=765 n=3, fldLen=180, typ=MSH, ro=2, nr=ID, pos=827 n=4, fldLen=20, typ=ST, ro=REQ, nr=NO_RPT, pos=880 n=4, fldLen=80, typ=ST, ro=OPT, nr=NO_RPT, pos=935 n=4, fldLen=15, typ=NM, ro=OPT, nr=NO_RPT, pos=991 n=4, fldLen=1, typ=ID, ro=OPT, nr=NO_RPT, pos=1044 n=3, fldLen=1, typ=MSA, ro=3, nr=ID, pos=1104 ------------------------------------------------------------------------------ -- ------------------------------------------------------------------------------- .---- Fred Smith / Office: fred AT computrition DOT com ( /__ ,__. __ __ / __ : / 508-663-2524 / / / /__) / / /__) .+' Home: fredex AT fcshome DOT stoneham DOT ma DOT us / / (__ (___ (__(_ (___ / :__ 617-438-5471 -------------------------------- Jude 1:24,25 ---------------------------------