string comparisons in C
Richard E. Covert
covertr at gtephx.UUCP
Fri Jul 14 08:30:56 AEST 1989
This is not a flame.
Mark Williams C is a wonder. The manual is so full of GEM/AES/VDI
hints that it still amazes me after two years! Anyway, C has a lack of good
string handling operations, so you need to use library functions. I was writing
a program in which I needed to determine whether a certain file type was a
member of a desired set. So, how do you do string comparisons in C?? The
normal, portable, way is to do a char search and match. Slow and ugly.
But, I was browsing thru the MWC manual, and lo and behold I see
pnmatch(). Now pnmatch is a wonderful little function which does string
comparisons. And it even accepts wildcards, so I was in business. I just
build an array of strings such as "*.PI1", and then by looping thru the
array I can string compare a user inputted filename against the list of
legal filetypes. Pretty neat solution.
So, the moral of this little ditty, is READ YOUR MANUAL!!
P.S. Does anyone know if pnmatch() is implemented on other C compilers??
Richard (gtephx!covertr) Covert
More information about the Comp.lang.c
mailing list