473,385 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C parser document

I'm trying to parse a configuration file,
this is the first time I'm trying something like this, and it seems hard.
C's I/O functions are a mess and hard to use , that is if you want to
write code in a good way.
I've tried google many times looking for some good document article that
talks about C I/O and parsing files, most of the docs that I came across
just talk about basic I/O things I can also learn from reading my man pages.

Any kind of advise is welcome!
Nov 15 '05 #1
9 1496
Jonas Geiregat wrote:
I'm trying to parse a configuration file,
this is the first time I'm trying something like this, and it seems hard.
C's I/O functions are a mess and hard to use , that is if you want to
write code in a good way.


I've written parsers for one style of config file in C; the I/O
functions were pretty much a non-issue.

Be more specific about what you're trying to parse and the problems
you've had.

--
Chris "electric hedgehog" Dollin
Almost all predictions about life in 2015 are wrong in some fundamental
respect.
Nov 15 '05 #2
ajm
I hardly think the I/O functions "are a mess" (not at all sure though
what you mean by that ;) but guess you still have a bit of reading
ahead of you...ho hum so give the following a try:

http://www.gnu.org/software/libc/manual/html_node/

for a start (I/O Overview and I/O Streams are what you might be looking
for and the rest probably doesn't hurt), then of course there are the
manpages etc. etc.

if you ever get around to a specific question you might want to post
that too ;)

hth,
ajm.

Nov 15 '05 #3
Jonas Geiregat wrote:
I'm trying to parse a configuration file,
this is the first time I'm trying something like this, and it seems
hard. C's I/O functions are a mess and hard to use , that is if you
want to write code in a good way. I've tried google many times
looking for some good document article that talks about C I/O and
parsing files, most of the docs that I came across just talk about
basic I/O things I can also learn from reading my man pages.

Any kind of advise is welcome!


Here's my advice. This is probably one of the worst posts I've seen to
this group. You don't describe what you are trying to do. You don't say
what problems you have. You gratuitously insult the programming
language you are trying to get help in.

Please read the following. It is not from our FAQ list, rather from
comp.lang.c++, but I cribbed it anyway:

Post compileable code: avoid ellipses, such as void f() { ... }

Post complete code: put in all necessary #includes and declarations of
needed types and functions

Post minimal code: just enough to demonstrate the problem

Post one compilation unit: if possible, combine Foo.h into Foo.c

Post the exact messages you received; differentiate between compiler,
linker, and runtime messages

Make sure main() has a return type of int, not void!

Brian
Nov 15 '05 #4
"Default User" <de***********@yahoo.com> writes:
Jonas Geiregat wrote:
I'm trying to parse a configuration file,
this is the first time I'm trying something like this, and it seems
hard. C's I/O functions are a mess and hard to use , that is if you
want to write code in a good way. I've tried google many times
looking for some good document article that talks about C I/O and
parsing files, most of the docs that I came across just talk about
basic I/O things I can also learn from reading my man pages.

Any kind of advise is welcome!


Here's my advice. This is probably one of the worst posts I've seen to
this group. You don't describe what you are trying to do. You don't say
what problems you have. You gratuitously insult the programming
language you are trying to get help in.


I've seen *much* worse posts than that.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #5
Keith Thompson wrote:
"Default User" <de***********@yahoo.com> writes:

Here's my advice. This is probably one of the worst posts I've seen
to this group. You don't describe what you are trying to do. You
don't say what problems you have. You gratuitously insult the
programming language you are trying to get help in.


I've seen much worse posts than that.


Worseness is in the eye of the beholder.

Brian
Nov 15 '05 #6
"Default User" <de***********@yahoo.com> writes:
Keith Thompson wrote:
"Default User" <de***********@yahoo.com> writes:
> Here's my advice. This is probably one of the worst posts I've seen
> to this group. You don't describe what you are trying to do. You
> don't say what problems you have. You gratuitously insult the
> programming language you are trying to get help in.


I've seen much worse posts than that.


Worseness is in the eye of the beholder.


Sure, but things like that tend to reinforce comp.lang.c's
(undeserved, IMHO) reputation as a bunch of overly picky topicality
police.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #7
Default User wrote:
Jonas Geiregat wrote:

I'm trying to parse a configuration file,
this is the first time I'm trying something like this, and it seems
hard. C's I/O functions are a mess and hard to use , that is if you
want to write code in a good way. I've tried google many times
looking for some good document article that talks about C I/O and
parsing files, most of the docs that I came across just talk about
basic I/O things I can also learn from reading my man pages.

Any kind of advise is welcome!

Here's my advice. This is probably one of the worst posts I've seen to
this group. [...]


For your information, it is considered polite to lurk
on a newsgroup for a few weeks before starting to post. If
you have seen nothing worse than the O.P., you cannot have
been here more than a few seconds. Patience, Grasshopper.

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 15 '05 #8

Jonas Geiregat wrote:
I'm trying to parse a configuration file,
this is the first time I'm trying something like this, and it seems hard.
C's I/O functions are a mess and hard to use , that is if you want to
write code in a good way.
I've tried google many times looking for some good document article that
talks about C I/O and parsing files, most of the docs that I came across
just talk about basic I/O things I can also learn from reading my man pages.

Any kind of advise is welcome!


It would help a bit if you could tell us what kind of problems you're
running into; what's the structure of the file you're trying to parse,
for example?

Advice on C I/O routines:

1. Avoid gets() like the plague. Better yet, just pretend gets()
never existed. Using it *will* introduce a point of failure in your
code.

2. Unless your input is relatively simple in structure and *always*
well-formed, don't use scanf() to read and assign items directly from
the stream; scanf() doesn't give you the ability to easily recognize or
recover from malformed input.

3. Use fgets() to read in lines of input, and then process the
resulting buffer with strtok(), strstr(), strchr(), sscanf(), or some
combination of the above. Alternately, use fgetc() to read in a single
character at a time and process via state tables, but unless you're
writing a compiler front-end or something similar, that's probably
overkill. And if you *are* writing a compiler front-end, use lex and
yacc or something similar instead of rolling your own.

4. Break your parsing code into several layers of abstraction, with
the C I/O routines wrapped in more abstract operations like
GetNextLine() or GetNextToken(), which are in turn called by
progressively more abstract operations like GetLogfileName() or
GetStartupParams(). This makes code a bit easier to write; you're only
focusing on as much complexity as you need to at any particular level.
It also allows you to make changes at the native input level without
hacking the application logic.

5. Before starting *any* of this, make sure there isn't a tool already
out there to do what you're doing. For example, if your input is in
XML format, there are already a number of parser libraries available
for parsing XML documents. And there are tools like the previously
mentioned lex and yacc (flex and bison in the GNU world) that allow you
to build robust and sophisticated parsers.

6. Of course, make sure you're using the right tool for the job in the
first place. The old joke goes something like "when confronted with a
problem, a programmer says, 'I know, I'll use XML.' The programmer now
has two problems. " XML's wonderful, but do you *really* need to link
in a heavyweight DOM parser to handle 5 lines of text? Do you really
need to go through the hassle of generating code from lex and yacc if
all you're dealing with is a comma-delimited list of name-value pairs?
This is why it's important for you to give us some idea of what you're
trying to do.

Nov 15 '05 #9

Eric Sosman wrote:
Default User wrote:

Here's my advice. This is probably one of the worst posts I've seen to
this group. [...]


For your information, it is considered polite to lurk
on a newsgroup for a few weeks before starting to post. If
you have seen nothing worse than the O.P., you cannot have
been here more than a few seconds.


Ha ha.

Believe me, I'm sincere. I rate this worse than troll posts or even
ERT's bad advice posts, because this person's post so utterly fails to
accomplish anything useful for him.

Brian

Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: annoyingmouse2002 | last post by:
Hi there, sorry if this a long post but I'm really just starting out. I've been using MSXML to parse an OWL but would like to use a different solution. Basically it reads the OWL (Based on XML)...
1
by: Vineeth | last post by:
Hi, I am using xerces2.6.0 and am developing a program for converting an xml document to a text file. My program is extending the DefaultHandler. The first problem I am facing is that even...
9
by: Stuart J. Shillinglaw | last post by:
With this page http://shillinglaw.atspace.com/ as the subject, the validator http://www.cogsci.ed.ac.uk/~richard/xml-check.html says the page appears to be not well formed, but selecting the Xerces...
4
by: billcoumbe | last post by:
any recommendations? I'm looking for something that will just run from the unix command line to validate large (20-50Mb) XML files against an XML DTD. Ideally something that is actively...
7
by: Michael | last post by:
Hi, I have a problem parsing XML file using XSLT stylesheet by using : using System.Xml; using System.Xml.XPath; using System.Xml.Xsl; // load Xsl stylesheet XslTransform myXslTrans = new...
2
by: David Virgil Hobbs | last post by:
Loading text strings containing HTML code into an HTML parser in a Javascript/Jscript I would like to know, how one would go about loading a text string containing HTML code, so as to be able to...
3
by: Harry | last post by:
Hello, I want to know if I can modify a xml-file with a xml-parser or can I only read the information out of it. If it is possible, I searching for xml-Parser for c++ (win32). I tried with...
4
by: ChillyRoll | last post by:
Hello guys, I am looking for a parser in PHP that can return all the attributes of XML entities. I know how to read the XML Entities, but I have got a problem with reading attributes. So I will...
4
by: fbrewster | last post by:
I'm writing an HTML parser and would like to use Internet Explorers DOM parser. Can I use Internet Explorers DOM parser through a web service? thanks for the help
6
by: Naresh Agarwal | last post by:
Hi I have been using DOM parser to create XML documents. I want to use an alternate mechanism to create XML document as size of my XML document is large and I don;t want the overhead of DOM...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.