Thread: Data validation

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    329

    Data validation

    Hi,

    I want to check that user input is a letter only. I have managed to trap it for lower case vs upper case using this code:

    Code:
    if ("%d" > 64 || "%d" < 91, letter, letter)
      {
      letter = letter+32;
      }
    I also want to prompt the user to enter a correct letter in case they choose a number or a symbol. Can this be done the same way by manipulating the ascii table? I have no issue doing that except for the characters between the lower case and uppercase letters....is there a way to isolate those characters using logical operators? I hope I make sense!!

    Thanks

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    I have managed
    Do you mean this code works for you?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    Quote Originally Posted by vart View Post
    Do you mean this code works for you?
    Doh!!! Nope doesn't work! It now accepts the upper case letters, but not the lower case letters!!!

    Are you able to point me in the right direction as to what I should be looking for?

    Thanks

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    138
    the c library already has functions that do this. in ctype.h the tolower function will return the lower case equivalent or the same character if there isn't a lower case equivalent. the toupper function does the opposite of tolower. if you just want to check the case, isupper and islower will do that, and if you want to check for a letter, isalpha does that.

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    Excellent...thanks for that....Will check now

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The "%x" stuff doesn't work for if statements!
    Please consult your books again.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. Replies: 3
    Last Post: 04-18-2008, 10:06 AM
  3. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  4. Binary Tree, couple questions
    By scoobasean in forum C Programming
    Replies: 3
    Last Post: 03-12-2005, 09:09 PM
  5. data validation
    By Loraswish in forum C++ Programming
    Replies: 7
    Last Post: 03-13-2003, 10:43 AM