linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mohammed Khalid Ansari <khalid@ncst.ernet.in>
To: Elias Athanasopoulos <eathan@otenet.gr>
Cc: Glynn Clements <glynn.clements@virgin.net>,
	linux-c-programming@vger.kernel.org
Subject: Re: parsing with fscanf().
Date: Thu, 12 Sep 2002 12:55:47 +0530 (IST)	[thread overview]
Message-ID: <Pine.LNX.4.33.0209121254590.309-100000@soochak.ncst.ernet.in> (raw)
In-Reply-To: <20020911230840.B1167@neutrino.particles.org>


Hello,

Is there any site which gives an extensive tutorial on lex/yacc?

with regards...

-- 

**************************************************************************

Mohammed Khalid Ansari                    Tel (res) : 0091-022-3051360
Assistant Manager II                          (off) : 0091-022-2024641
National Centre for Software Technology   Fax       : 0091-022-2049573 
8th flr,Air India Build. Nariman Point,   E-Mail    : khalid@ncst.ernet.in 	
Mumbai 400021.

Homepage : http://soochak.ncst.ernet.in/~khalid			  	  

**************************************************************************

On Wed, 11 Sep 2002, Elias Athanasopoulos wrote:

> On Wed, Sep 11, 2002 at 08:36:04PM +0100, Glynn Clements wrote:
> > fscanf() is worthless when the data doesn't adhere to a rigid format. 
> > One of the main problems is that, even when it isn't entirely
> > successful, it consumes some of the data from the stream.
> > 
> > A better solution is to read whole lines (e.g. with fgets), then parse
> > it with sscanf(). That way, if sscanf() fails, you can try again with
> > the same data. E.g.
> > 
> > 	for (;;)
> > 	{
> > 		char buff[81];
> > 		fgets(buff, sizeof(buff), fp);
> > 		if (sscanf(buff, "%d %d %f", &i1, &i2, &f) == 3)
> > 			continue;
> > 		if (sscanf(buff, "%d %f", &i1, &f) == 2)
> > 			continue;
> > 		error();
> > 	}
> 
> Thank you. I was up to write something like that, but I wasn't sure and
> was ready to give up and go traditionaly with read(). ANW, thanks for
> the above code, it helps a lot. :-)
> 
> > If you ever need to write a real parser, learn lex/yacc.
> 
> Nah... it is for a short report, a project that I want to spend as less
> time as I can. 
> 
> Elias
> 
> 


  reply	other threads:[~2002-09-12  7:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-11 18:24 parsing with fscanf() Elias Athanasopoulos
2002-09-11 19:36 ` Glynn Clements
2002-09-11 20:08   ` Elias Athanasopoulos
2002-09-12  7:25     ` Mohammed Khalid Ansari [this message]
2002-09-12  7:21       ` Carlos Fernández
2002-09-11 22:14 ` Richard Webb

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.33.0209121254590.309-100000@soochak.ncst.ernet.in \
    --to=khalid@ncst.ernet.in \
    --cc=eathan@otenet.gr \
    --cc=glynn.clements@virgin.net \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).