strings making sure user has entered some info

This is a discussion on strings making sure user has entered some info within the C++ Programming forums, part of the General Programming Boards category; hi, im learnin c++ so i dont know much about it at the moment, but i have an assignment from ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02: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, 02:59 AM
  4. Replies: 3
    Last Post: 12-15-2001, 12:46 PM
  5. use user entered formula to calculate something
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 12-07-2001, 01:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21