Is There A Way To Check If argv[1] Is An Integer?

Karl Heuer karl at haddock.ima.isc.com
Thu Dec 21 10:16:33 AEST 1989


In article <11467 at csli.Stanford.EDU> poser at csli.stanford.edu (Bill Poser) writes:
>In article <984 at ux.acss.umn.edu> eric at 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 at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list