I have another problem. I have simple function below which check to see if the argument enter at the command line is a valid number. This function work fine with possitive integer, but I want it to accept floating point number as well. The floating point number can include "+" and "-" sign, and decimal point. I'll take a crack at this, even thought it looks like a homework problem. (should have been due by now, right? Maybe that's a general way to handle this sort of thing...) /******************************************************************** * check_valid_number: this function checks each character in * * string to ensure that it is a valid * * digit. It return 1 if string makes a * * valid number, zero otherwise. * * * * char_string : a string to be tested if it is a valid * * digit * * * * Return : 1 if string makes a valid number, * * zero otherwise. * ********************************************************************/ int check_valid_number(char *char_string) { int count, length; /* count the number of character in the string */ length = strlen(char_string); /* go through each character and check whether it is a valid digit */ for(count = 0; count < length; count++) if (!isdigit(*(char_string + count))) return 0; /* return 1 if it is a valid number */ return 1; } /* end of check_valid_number */ The "meat" of the routine is sort of classic "ugly" C code: for(count = 0; count < length; count++) if (!isdigit(*(char_string + count))) return 0; return 1; While there's nothing WRONG with this, exactly, and it's not really hard to read, it has been written 'concisely' to the point where it is less than obvious how to extend it in the fashion you ask about. First of all, it's not "blocked" to add statements to, and secondly, the way it checks for ILLEGAL character make it harder to extend algorithmicly. One way to extend this would be: for(count = 0; count < length; count++) { char thischar = *(char_string+count); /* * check for legal non-digit characters */ if (thischar == '.') continue; /* decimal ok - continue loop */ if (thischar == '+') continue; /* plus sign ok - continue loop */ if (thischar == '-') continue; /* minus sign ok - continue loop */ /* * having eliminated "special" characters, the only remaining * legal characters are digits. */ if (!isdigit(thischar)) return 0; } /* * We looped through all characters and didn't find anything illegal * Therefore the number is OK. */ return 1; I don't like the extra variables, or the mixture of "positive and negative logic", and I probably would have written something like: while ((thischar = *char_string++) != 0) { /* * check for legal non-digit characters */ if (thischar == '.') continue; /* decimal ok - continue loop */ if (thischar == '+') continue; /* plus sign ok - continue loop */ if (thischar == '-') continue; /* minus sign ok - continue loop */ if (isdigit(thischar)) continue; /* digits are legal */ /* * other checks for legal characters go here. */ return 0; /* illegal character - get out now */ } /* * We looped through all characters and didn't find anything illegal * Therefore the number is OK. */ return 1; This eliminates both "length" and "count" (which I don't think would be optimized away by anything but the most advanced compiler.) Use of *p++ is likely to be well-optimized to irregularities in most processors instruction sets, since it's very common. Some people object to assignments in the conditional of a while statement, and some people don't like "continue", but that's what I'd have done. You COULD use logical operators: if ((thischar == '.') || (thischar == '+') || (thischar == '-')) continue; /* assorted puncuation ok - continue loop */ Or even (from the original) for(count = 0; count < length; count++) if (!(isdigit(*(char_string + count)) || (thischar == '.') || (thischar == '+') || (thischar == '-'))) return 0; But the code is very likely to be the same, and it has the same sort of "difficult to extend" problems as the original, and starts to get difficult to read easilly. IMO. BillW -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu