473,804 Members | 3,278 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1517
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_Keit h) 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_Keit h) 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
GetStartupParam s(). 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
4266
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) and puts values in a number of arrays and then puts the contents of the array in a HTML table. I'd like to keep the array structure. I've checked out all sorts of different javascript parsers but have not met with a great deal of success with any...
1
2346
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 though I have turned the Validation feature off, the SAX parser still needs the DTD to be present. If I remove the DOCTYPE declaration from the XML file then it raises an exception for unparsed entities. If I provide a zero byte DTD then the SX parser...
9
1545
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 parser at http://valet.webthing.com/page/ shows the page to be valid and well formed. What does the RXP parser require that the others do not? The standalone declaration seems to be the issue, and a standalone document is what I am trying to...
4
3091
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 supported and has good documentation! If there's nothing suitable for Solaris a command line program for Windows might do - currently using XMetaL/XMLSpy parsers which aren't really suited to large files.
7
3391
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 XslTransform() ;
2
2680
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 use javascript or Jscript to work with the HTML code in the text string, in the same way that one works with XML code in a text string using the XML parser. If I was able to load the text string containing the HTML code succesfully, I would be...
3
2226
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 xerxes. But I didn't find how to access to existing "const" Methods. I also don't know if I can modify? Thanks very much!
4
3222
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 appreciate if you could give a parser that can return all the Entities and Attributes of respective entities as an array. For e.g.: <?xml version="1.0" ?>
4
2572
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
8151
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 (where entire tree in constructed in memory). Like SAX APIs for parsing XML documents, Is there any thing like SAX parser/APIs for creating XML documents?
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9582
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10580
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.