Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wala

macrumors member
Original poster
Jun 3, 2005
46
0
What would be a normal way to, say, parse a string from a configuration file for a program written in C? Would it simply be a series of while loops, eg, in the case of getting past whitespace, something like:
PHP:
while(*string && isblank(*string))
    string++;
Or are there standard libraries and tools which should be used to parse strings besides functions like strtok()?
 

bronxbomber92

macrumors regular
Nov 23, 2006
109
0
I would say these would provide the combination of functions (and good memory management) to do what you want (and more)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
 

wala

macrumors member
Original poster
Jun 3, 2005
46
0
I would say these would provide the combination of functions (and good memory management) to do what you want (and more)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
What is the current official recommendation regarding malloc.h? I haven't seen much code which uses that #include....
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
It almost seems as though there as many "right" ways to do this as there are programs, everyone feels the need to reinvent this stuff. Once upon a time this kind of made sense, but there are good standardised alternatives today.

On the Mac, you can use property lists, all the hairy code is already written. On Windows, use the registry. On "plain" Unixy systems, there are lots of nice libraries around that will handle XML, LanMan-style .ini files, and many more (and those would be fine with the Mac and Windows too, if you want a single implementation).
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
What is the current official recommendation regarding malloc.h? I haven't seen much code which uses that #include....

That's not surprising, because malloc, calloc, realloc and free are included in stdlib.h.
 

edm

macrumors newbie
Dec 27, 2006
4
0
Austin, TX
Regex

Seems like there would be a Regular Expressions library available in C that would handle all all your parsing needs.
 

wala

macrumors member
Original poster
Jun 3, 2005
46
0
How would I use regexec's substring matching feature? (I cannot seem to find understandable documentation for it)
Examples would be nice....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.