Limiting space

This is a discussion on Limiting space within the C++ Programming forums, part of the General Programming Boards category; #include <iostream> using namespace std; struct date { int month[2]; int day[2]; int year[4]; char dummy[1]; }; I understand that ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    6

    Limiting space

    #include <iostream>
    using namespace std;

    struct date
    {
    int month[2];
    int day[2];
    int year[4];
    char dummy[1];
    };


    I understand that that is an array. what im trying to accomplish is to set the number of characters inputed to 2 for month. for example, the above will ask: Please enter your birthdate (mm/dd/yyyy)
    my cin statement will be:
    cin >> birthdate.month >> birthdate.dummy >> birthdate.day . . . and so on.

    when the user inputs the birthdate (02/17/2003), i want the 02 to be the month, '/' to be the dummy character, 17 to be the day, and 2003 to be the year.
    i hope this makes sense. please help!!

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    are you asking the user to enter it in as 02/17/2003, and it to disregard the slashes. best way is to read it into a string, parse the string and place each part into its respective array. that or keep it as it is, just separate the date by a space, and forget the slash marks.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    6

    exactly

    Thats what i want to do is to read in the date and ignore the slashes. BUT we havent reached that far in class where we take in arrays and strings. basically, i have to read the 02 from the entire input and store that in month, then ignore the slashes and do the same for the day and the year. my only problem is that when the user (me) inputs the date in that form (mm/dd/yyyy), my program freezes. its taking the entire input as mm. i know it might be primitive for you guys, but we all have to start somwhere!

  4. #4
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Yeah, you can't do it the way you are doing it. If you want the user to be able to enter it with slashes, then you need to read in a string and then parse it.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    just enter it with no slashes. your code will work that way. 02 17 2003. it will enter it in to the respective array.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Out of space when compiling kernel
    By NuNn in forum Linux Programming
    Replies: 3
    Last Post: 04-01-2009, 02:43 PM
  2. disk space mysteriously gone
    By evader in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2004, 12:30 PM
  3. Replies: 12
    Last Post: 05-17-2003, 05:58 AM
  4. someone who is good at finding and fixing bugs?
    By elfjuice in forum C++ Programming
    Replies: 8
    Last Post: 06-07-2002, 03:59 PM

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