#include <is.h>

Wietse Z. Venema wietse at wzv.UUCP
Thu Dec 22 08:38:04 AEST 1988


In article <354 at greens.UUCP> matthew at sunpix.UUCP ( Sun NCAA) writes:
>                                                         But no where could
>I find a function to validate the string to see if it did contain a number
>that atof(); would correctly interpret.
>...
>[BTW, isfloat(); can double for isdouble(); as can isint(); for islong();]
>

int isfloat(s)	/* wants a null-terminated string with f.p. number */
char *s;
{
	char junk = 0;
	float fval;

	return (sscanf(s,"%f%c",&fval,&junk) == 1);
}

Of course, you will want to keep the result of the string-to-float
conversion.
-- 
work:	wswietse at eutrc3.uucp	| Eindhoven University of Technology
work:	wswietse at heitue5.bitnet	| Mathematics and Computing Science
home:	wietse at wzv.uucp		| 5600 MB Eindhoven, The Netherlands



More information about the Comp.lang.c mailing list