There are a number of routines in 'C' that convert ascii to int/long/etc. for you. Very useful. Problem is, they return '0' when there's an error! Here's where exception handling would really solve the problem. Well, here's how I attempted to get around this problem 'cheap and dirty'. I'm sure there's a better way in straight 'C', and if so please post it!
BOOL isOkULONG( char* inputBuf, ULONG* result)
{
//char copyBuf[MAX_PATH];
LONG readInLong;
readInLong = strtoul(inputBuf, NULL, 0);
if (errno == ERANGE)
{ return FALSE;
}
// if we get a zero, make sure there's actually a zero in the
// string. Otherwise, we might've just gotten whitespace or some
// garbage. This isn't totally foolproof but should catch most
// of the cases.
if (readInLong == 0 && strrchr( inputBuf, '0' ) == NULL)
{ return FALSE;
}
*result = readInLong;
return TRUE;
}
--
MattWalsh - 27 Feb 2002