View Single Post
Old 03-18-2005, 06:58 AM   #1 (permalink)
keeling
Registered User
 
Join Date: Mar 2005
Posts: 4
keeling is on a distinguished road
[C]IsNumeric: Will this work?

Please forgive me if this is a 'dumb' question, but I am not much of a C coder.

I am working on some routines to be used in a different language. One of the routines I want is a check to see if a string is numeric (like the VB command). This is what I have come up with:

Code:
int IsNumeric(char *pString){
	char *pEnd;
	double dbl;
	dbl = strtod (pString,&pEnd);
	if (pString != pEnd && *pEnd == '\0'){
		//it is numeric
		return 0;
	}
	else{
		//it isn't
		return -1;
	}

}
I have tried a few tests with it and it seems to work, but I am great for over looking obvious.

Thanks for helping a bad c coder.

Last edited by Valmont; 03-18-2005 at 08:40 AM.
keeling is offline   Reply With Quote