Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!ucsd!chem.ucsd.edu!tps From: tps@chem.ucsd.edu (Tom Stockfisch) Newsgroups: comp.lang.c Subject: Re: Is There A Way To Check If argv[1] Is An Integer? Message-ID: <636@chem.ucsd.EDU> Date: 22 Dec 89 08:30:45 GMT References: <984@ux.acss.umn.edu> <11467@csli.Stanford.EDU> Reply-To: tps@chem.ucsd.edu (Tom Stockfisch) Organization: Chemistry Dept, UC San Diego Lines: 31 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: >>I need a way to determine if argv[1] (or any argument) is an integer. >int >is_integer(string) >char *string; >{ > return(regexec(regcomp("[-+]?[0-9]+"),string)); >} How about int /* really BOOL */ isInteger(string) char *string; { char *endptr; (void)strtol( string, &endptr, 10 ); return endptr != string; } >(I now await flames on errors in the regular expressions.) > Bill How about flames on requiring unnecessary software? -- || Tom Stockfisch, UCSD Chemistry tps@chem.ucsd.edu