Date: Tue, 10 Nov 1998 10:26:33 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: Sahab Yazdani cc: djgpp AT delorie DOT com Subject: Re: Parsing... In-Reply-To: <364778A4.86092F30@geocities.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com On Mon, 9 Nov 1998, Sahab Yazdani wrote: > #include > > to this string > > stdio.h If this is as simple as it sounds, just use `sscanf', like this: sscanf (buffer, " # include <%[^>]> \n", parsed_string); (It's amazing how many people overlook the tremendous power of formatted input!) For bullet-proof code, test the value returned by `sscanf': it should be 1 if all's well; if it's not, back up and recover. Note that the C Standard allows whitespace both before and after the leading `#', and sscanf will eat up zero or more whitespace characters when it sees a blank in the format string. That is why the format above looks a bit strange at first sight. > BTW if you are wondering why I would want to start parsing C/C++ files, > I'm doing it because I want to start developing a Source Browser for > DJGPP If that is your goal, I would suggest to get as much help as you can from the available tools instead of reinventing the wheel. For example, the -M option to GCC will cause it to generate all the information about header files included by a given source file, in a format that's much easier to read. In those cases where you do need to read the source, I'd suggest to use Flex if you need to parse the file. Flex will generate C code which is much faster in the case where the source file must be parsed for multiple alternatives. (A port of Flex is avialable in v2gnu/flx254b.zip from the usual DJGPP sites.)