Greetings.
In article <bm**********@chessie.cirr.com>, Christopher Benson-Manica wrote:
Note that C isn't particularly well-suited for intensive text processing,
though; unless it's being integrated in a much larger C program, it would
be better and faster to write the sort of application you describe using
some regexp-based tool such as sed or perl.
Why do you say that? (note that this is an honest question, not a
challenge)
It's simply a question of specialization of tools. It's certainly possible
to drive in a nail using the blunt end of a screwdriver, though it would be
faster and less accident-prone to use a hammer. Likewise, building
applications (even small ones) which deal almost exclusively with text
processing is usually more efficient (with respect to development time and
ease of debugging, not necessarily execution speed) when using a language
specifically devoted to that task. A program to do regular expression
search-and-replacement on multiple files is literally four characters long
in sed (not counting the filenames and regular expressions themselves); the
corresponding program in C would necessarily be several lines long, even if
one used a third-party regexp library. You would need to include the
regexp and stdio headers, define the main function, declare a file pointer,
open each file in argv[] for reading (including error checking), loop
through each line of the file, do the regexp replacement, write out the new
line, close the file, and finally return from main. Sure, the compiled C
program might run a hundred times faster than the corresponding interpreted
sed or perl code, but if it's just a one-off program, you've just wasted
five minutes to write the C program plus 0.00001 seconds to run it versus
spending five seconds to write the sed program plus 0.001 seconds to run
it.
Regards,
Tristan
--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\
http://www.nothingisreal.com/ >< To finish what you