Thread: Valadating letters

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    59

    Valadating letters

    Hi guys,

    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,

    Code:
    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
             {
             return convertnum1;
             }
    
             else
             {
             calc(); // calls calculation function
             }
             return 0;
             } // 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

    Boontune

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    88
    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
    Hope you don't mind my bad english, I'm Austrian!

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    59
    Thanks for the help...

    Boontune

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    59
    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?

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Open your ctype.h file! You can see what there is in it, (and there are morew than two more).
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generating random letters
    By ominub in forum C Programming
    Replies: 6
    Last Post: 04-29-2009, 01:12 AM
  2. need to count individual letters in input
    By epox in forum C Programming
    Replies: 12
    Last Post: 05-22-2006, 06:32 AM
  3. Counting letters and digits
    By FeNCinGeR in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2006, 11:39 AM
  4. drive letters
    By metsman20 in forum Tech Board
    Replies: 4
    Last Post: 12-11-2003, 12:54 PM
  5. Switching letters
    By XiReDDeViLiX in forum Windows Programming
    Replies: 4
    Last Post: 06-06-2002, 06:48 AM