[comp.lang.c] ATTN: C hacker who loves Awk

ajayshah@alhena.usc.edu (Ajay Shah) (05/06/91)

I'm an experienced Awk programmer who's recently started on C.
The biggest thing I miss is the split() function.  If you have
written some such function, could you please donate it to me?  It
will make my life a lot happier.

Thanks,

	-ans.


P.S.: int split(char *s, char **words, char FS)

	takes string s and field seperator FS.  Generates array of
	words in words, function returns number of fields found.
	Weird special hacks:

		- multiple consecutive blank FS are ignored
			e.g. split("this    is", words, " ") will give
			fields "this", "is".
		- any other multiple FSs are respected
			e.g. split("this||||is", words, "|") will give
			fields "this", "", "", "", "is.

-- 
_______________________________________________________________________________
Ajay Shah, (213)734-3930, ajayshah@usc.edu
                             The more things change, the more they stay insane.
_______________________________________________________________________________

dauerbach@cup.portal.com (David Dave Auerbach) (05/11/91)

Dr, Dobbs Journal had an article last year about AWK extensions to C.
I don't have it handy here in the office and I don't remember what functions
(or which issue) they created.  It was something I saved for future use
since I use awk a lot too.
-dave

pete@indep1.MCS.COM (Peter Franks) (05/14/91)

Take a look at the function 'strtok'.  It should be a reasonable excercise
for you to use it to write your own 'split' function.  You'll learn more by
doing it yourself than you would by getting it handed to you.  *:^)