parsing date strings mm/dd/yy??

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2005
Posts: 7
Reputation: fiberoptik is an unknown quantity at this point 
Solved Threads: 0
fiberoptik fiberoptik is offline Offline
Newbie Poster

parsing date strings mm/dd/yy??

 
0
  #1
Mar 29th, 2005
I have a program to write that takes in the date in ##/##/## format. I then write the month day, year output. What I'm totally lost on is how to get from reading the char array to integer numbers?? Big time Lost! Need help!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,761
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 740
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Code Goddess

Re: parsing date strings mm/dd/yy??

 
0
  #2
Mar 29th, 2005
Is this C or C++?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 7
Reputation: fiberoptik is an unknown quantity at this point 
Solved Threads: 0
fiberoptik fiberoptik is offline Offline
Newbie Poster

Re: parsing date strings mm/dd/yy??

 
0
  #3
Mar 30th, 2005
c++, guess I should have included that.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,761
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 740
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Code Goddess

Re: parsing date strings mm/dd/yy??

 
0
  #4
Mar 30th, 2005
Here's a start:
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. istringstream in ( "03/30/05" );
  11. int m, d, y;
  12.  
  13. in>> m;
  14. if ( in.peek() != '/' ) {
  15. cerr<<"Invalid format"<<endl;
  16. return EXIT_FAILURE;
  17. }
  18.  
  19. in.ignore();
  20. in>> d;
  21. if ( in.peek() != '/' ) {
  22. cerr<<"Invalid format"<<endl;
  23. return EXIT_FAILURE;
  24. }
  25.  
  26. in.ignore();
  27. in>> y;
  28.  
  29. cout<< m <<' '<< d <<' '<< y <<endl;
  30. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 7
Reputation: fiberoptik is an unknown quantity at this point 
Solved Threads: 0
fiberoptik fiberoptik is offline Offline
Newbie Poster

Re: parsing date strings mm/dd/yy??

 
0
  #5
Mar 30th, 2005
Thanks for the code, however, I'm really at a loss to how it works. We've not yet gone this far in C++, only arrays & some work with strings. Can I put a cout prompt & cin to input the date this way? ex.

cout << "Input date in format mm/dd/yy :\n";
char date[9];
cin >> date;

As I have to error check the date, and later output it in a function converting to monthname dd, 20##.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,761
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 740
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Code Goddess

Re: parsing date strings mm/dd/yy??

 
0
  #6
Mar 30th, 2005
>We've not yet gone this far in C++
Oh, so this is homework? In that case you'll need to show some effort in the form of an existing attempt, or detailed examples of what steps you went through while trying to figure out a solution and what you learned in the process. And posting here doesn't count.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC