problems with date entry

This is a discussion on problems with date entry within the C++ Programming forums, part of the General Programming Boards category; Hi everyone this is my first post, please be nice so i am writing a paintball booking program as a ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    11

    problems with date entry

    Hi everyone this is my first post, please be nice
    so i am writing a paintball booking program as a project i am doing allright but i have to check for invalid date entries in my input by reading the string input into a buffer that will accomodate the largest string size. At the moment the date is input into three seperate char arrays, dd, mm, yyyy. I am stumped as to how i can read the string input into a buffer to check for errors >.< i think i might need to use cin.read() but im not sure how this works and which arguements i should pass, thanks for your help

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    It sounds like you are using C style strings. There are functions available to find a character in a string (like '/') or tokenize based on a character. There are also functions to convert to integers so you can validate that the month is between 1 and 12 and stuff like that. I don't think you need cin.read() for that, just cin >> or getline.

    The same types of options are available with C++ strings and stringstreams which I find easier deal with and harder to mess up.

  3. #3
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Try this perhaps,

    http://www.daniweb.com/code/snippet367.html

    A useful snippet from one of our cprog members, if you might be having trouble handling actual dates.

    And I found this useful

    http://www.cprogramming.com/tutorial/string.html

    Code:
    string::iterator my_iter;
    for(my_iter = my_string.begin(); my_string != my_string.end(); my_iter++)
    {
        cout<<*my_iter;
    }
    If you use the iterator method look out for this little bug btw

    Code:
    string::iterator my_iter;
    for(my_iter = my_string.begin(); my_iter  != my_string.end(); my_iter++)
    {
        cout<<*my_iter;
    }
    Last edited by treenef; 10-17-2005 at 03:03 AM.

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    11
    thanks for your replies everyone i figured it'd be a simple cin with an array or with loops or something but the instruction is worded like this:

    •Check for invalid entries such as the length of the date string.
    Note: The string should be read into a buffer that will accommodate the longest string that can be entered at the keyboard.

    so i figured it'd be something complicated i guess not thanks for help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advancing Days
    By nhubred in forum C++ Programming
    Replies: 0
    Last Post: 06-01-2009, 06:22 PM
  2. Results for the Encryption Contest -- June 23, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 07-07-2002, 08:04 AM
  3. windows date...
    By Unregistered in forum Windows Programming
    Replies: 3
    Last Post: 03-17-2002, 06:50 PM
  4. Date class help!! Please
    By C++Newbie in forum C++ Programming
    Replies: 3
    Last Post: 11-12-2001, 12:31 PM
  5. Help Me Out!! Pls
    By Joanna in forum C++ Programming
    Replies: 5
    Last Post: 10-27-2001, 05:08 AM

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