Article View: comp.os.msdos.programmer
Article #2781Re: Quick Stream Field hack
From: Bryan So
Date: Wed, 24 Oct 1990 18:42
Date: Wed, 24 Oct 1990 18:42
34 lines
1539 bytes
1539 bytes
In article <9355@helios.TAMU.EDU> ctl8588@rigel.tamu.edu writes:
= Maybe someof you already know this, but there is a quick way to read
= in string fields from a stream. Simple use fscanf with the [^XYZ]
= format (look it up..d:) where X, Y and Z are end-of-field characters.
= I hope this saves someone a sleepless night. I can now do in two lines
= what use to take me 10 or so....and it only took me 5 years to stumble
= apon it while reading the run-time library manuals (what a dedicated
= guy! d:)
=
= For example, one can use the following to 'type' a DOS file...
=
= while(!feof(fh))
= {
= fscanf(fh,"[^\n] ",tempstr);
= printf("%s\n",tempstr);
= }
I think you need a "percent" in front of [^\n].
= WARNING!!! It is important to have the white space after the end bracket.
= If your end-of-field is not a white space I'm not sure what you would
= have to replace the space with......
You can use the following:
fscanf(fh, "%[^\n]%*c", tempstr);
%c will get any character from the stream. The * in between tells
fscanf to get rid of any character from the stream.
Bryan So
Technical Details
Message-ID:
<11561@spool.cs.wisc.edu>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!sun-barr!rutgers!uwvax!brownie.cs.wisc.edu!soReferences:
<9355@helios.TAMU.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!sun-barr!rutgers!uwvax!brownie.cs.wisc.edu!so From: so@brownie.cs.wisc.edu (Bryan So) Newsgroups: comp.os.msdos.programmer Subject: Re: Quick Stream Field hack Message-ID: <11561@spool.cs.wisc.edu> Date: 24 Oct 90 18:42:54 GMT References: <9355@helios.TAMU.EDU> Sender: news@spool.cs.wisc.edu Organization: U of Wisconsin CS Dept Lines: 34