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

Tom Stockfisch tps at chem.ucsd.edu
Fri Dec 22 19:30:45 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:
>>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 at chem.ucsd.edu



More information about the Comp.lang.c mailing list