Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!wuarchive!husc6!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Is There A Way To Check If argv[1] Is An Integer? Message-ID: <15494@haddock.ima.isc.com> Date: 20 Dec 89 23:16:33 GMT References: <984@ux.acss.umn.edu> <11467@csli.Stanford.EDU> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 13 In article <11467@csli.Stanford.EDU> poser@csli.stanford.edu (Bill Poser) writes: >In article <984@ux.acss.umn.edu> eric@ux.acss.umn.edu (Eric D. Hendrickson) >writes the equivalent of: >int is_integer(char *s) { return(regexec(regcomp("[-+]?[0-9]+"),s)); } I think regexp is a bit of overkill; I generally use strtol() for this. (Usually, once you've detected that the argument is in fact an integer, you need to evaluate it anyway, right?) And if you're on a backward system that doesn't have strtol(), it's not hard to write one. Compared to regexp, for instance. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint