Hi, I'm fairly new to C++. I've taken a class on it at a university but it really only went through the basic I/O, data structures, classes, and pointers. It wasn't very algorithm oriented. It was all very basic.

Here's the problem a friend of mine needed help with his C++ homework. He is attending a different institution than myself and instead of their being 4 classes covering C++ there's only 2. Meaning his one class is the equivalent of two semesters worth of C++ at my school (which isn't saying much to me right now about my school). Though my school does offer class on A.I. and various other things such as Compiler Design, but enough about that.

His homework problem is that he's given the source for a program which he has to add a new functionality to it. This functionality is to be to parse a date input from the user of the format "mm/dd/yy". I'm familiar with everything that would be used in the process such as classes, structs, poiters etc etc. But being able to develop the algorithm is beyond me. Unfortunately I wasn't able to help him in time. Meaning he ended up not turning in the homework. But even though he got a zero for this it is still bugging me and I must find out how to do it. I know it can't use the StringTokenizer or anything along those lines except for the basic stuff. Basic libraries are onyl be be sued such as iostream, fstream, cmath, you know the bare minimum. As you can tell the inputString array needs to be split up into 3 different arrays titled day,month,year. The delimiter in this case would be the '/'.

There are no C++ tutors at either school otherwise I would have gone to them first.

Here's a failed attempt at an algorithm which I thought would work but I get the wrong output. Just to give you an idea of the kid of algorithm I'm looking for. The compiler I'm using is Microsoft Visual C++ 6.0. Though I wouldn't mind using the gcc either.

char inputString[];
char month[2];
char day[2];
char year[2];
int i;

cout<<"Enter a date: (mm/dd/yy)"<<endl;

//It continues on for formatting, validation, and conversion 
//to different date formats.

Any help would be highly appreciated. If you feel uncomfortable about giving away solutions, hints and advice would also be very helpful.

Also, I have searched the forums but I may have missed something similar. If I did, a link would be nice as well.


I forgot to include the output I get from that algorithm I used: Here it is:

Month is mmddyy
Day is ddyy
Year is yy


Make the arrays big enough for the null terminator, and null terminate each.

This might also be of interest.

OMG!!!...lol. It was right there in front of my face. Thanks Dave. I just needed to insrease the size of the arrays from 2->3. Once again thanks alot Dave.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.