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!

Recommended Answers

All 5 Replies

Is this C or C++?

c++, guess I should have included that.

Here's a start:

#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main()
{
  istringstream in ( "03/30/05" );
  int m, d, y;

  in>> m;
  if ( in.peek() != '/' ) {
    cerr<<"Invalid format"<<endl;
    return EXIT_FAILURE;
  }

  in.ignore();
  in>> d;
  if ( in.peek() != '/' ) {
    cerr<<"Invalid format"<<endl;
    return EXIT_FAILURE;
  }

  in.ignore();
  in>> y;

  cout<< m <<' '<< d <<' '<< y <<endl;
}

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##.

>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.

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.