Below is my validation function, what it should do is check the length of num1 which is a string( bad name i know!) and also convert num1 to be a floating point number, then it should check to see if the length is less than or equal to 6, and in the range of 0 -1000,
What i also need to do in this function is to check that no letters have been entered,
float validation1() // validation1 function
length1 = strlen(num1); // Finds out length of string
convertnum1 = atof(num1); // converts string to float
if (length1 <= 6 && convertnum1 >= 0 && convertnum1 <= 1000) // check length & range
calc(); // calls calculation function
} // end of validation function
Does anybody know how this could be achieved?
i have heard of a function called isdigit(), would this be used?
Thanks alot guys
first of all: kick out that ugly global vars!
never ever use them
there is a 'function' (actually it is often a macro) isdigit() in ctype.h
it's easy to use: you call it with your char as param and it returns true (!0) if your char is a digit oder 0 otherwise :)
and beware: atof returns double not float
Thanks for the help...
What are the other two functions called with ctype.h?
i now there is:
isdigit() - for numbers
isalpha() - for letters
Can someone tell me what the other two are called?
for puncutation and space?
Open your ctype.h file! You can see what there is in it, (and there are morew than two more).