Tempo fa, in C, avevo fatto una cosa del genere:
int is_number( const char *s, int int_wanted ) {
int ok = 0; // !=0: is a number; ==0: is not a number
if( *s != '\0' ) {
int digit_found = 0;
int dec_pt_found = 0;
int sign_found = 0;
char dec_pt = *(localeconv()->decimal_point);
char th_sep = *(localeconv()->thousands_sep);
for( ok=1; *s; ++s ) {
if( *s != th_sep ) {
if( *s == '+' || *s == '-' ) {
if( !(ok=(++sign_found<2)&&(!digit_found)) ) break;
} else if( *s == dec_pt ) {
if( !(ok=(++dec_pt_found<2)&&(!int_wanted)) ) break;
} else if( isdigit(*s) ) {
digit_found = 1;
} else { ok = 0; break; }
}
}
}
return ok;
}
P.S. Leggere la frase di "firma" qui sotto!!!