Quote:Original post by rdansie
bool isStringNumber(char *str, int len){
bool returnResult = TRUE;
if((str[0] > '0') && (str[0] < '9')){
if(len > 0)
returnResult = isStringNumber(&(char[1]), len-1);
}else
returnResult = FALSE;
return returnResult;
}
If you're specifically offering a C solution, then great, I suppose (although your function has a couple of errors in it and really doesn't need to be recursive).
However (and this is editorializing a bit) I don't quite understand why people insist on posting hand-rolled, untested, unsafe, and/or non-standard solutions to threads like this
after the (arguably) correct solution has already been given.
Read the thread. The test can be performed in one line using boost, and if you don't like that Zahlman posted a nice alternative using functors and the standard library. If you're seriously proposing the above or something like it as a solution, I think you need to provide some supporting arguments as to why it's superior to what's already been suggested.
Anyway, I don't mean to be negative; really my motivation is just to clarify to those who might read this thread (and might not have the experience to sort the wheat from the chaff, as it were) that standardized solutions are generally to be preferred.