Thread: strings making sure user has entered some info

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    2

    strings making sure user has entered some info

    hi, im learnin c++ so i dont know much about it at the moment, but i have an assignment from college and i have to accept a string from the user, which i can do, but the problem i am having is this

    I must make sure some data is entered - how would i do this

    and it must be text only, the program should reject any other data

    please help

    thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well show us how you read stuff in, then perhaps we can tell you how to validate it

    > and it must be text only, the program should reject any other data
    Pretty much everything you can type at the keyboard would be regarded as text, can you be more specific (like alphabet chars only)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    2
    im using cgets to get information

    and only alphabet characters can be used, letters that would be used in names

    thanks

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So I'm guessing that a for loop to examine every character in the string, and using the isalpha() function in ctype.h would be something to try
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM
  3. Format User Input When using strings
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 03-08-2002, 03:59 AM
  4. Replies: 3
    Last Post: 12-15-2001, 01:46 PM
  5. use user entered formula to calculate something
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 12-07-2001, 02:21 AM