#include <cctype>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <ctime>
using namespace std;
void dateParse( string) ;
int main( )
{
string dte1 = "2/5/2014" ;
string dte2 = "2/15/2014" ;
string dte3 = "12/5/2014" ;
string dte4 = "12/15/2014" ;
string dts;
dateParse( dte1) ;
dateParse( dte2) ;
dateParse( dte3) ;
dateParse( dte4) ;
}
void dateParse( string date)
{
char day[ 2 ] = "" ;
char month[ 2 ] = "" ;
char year[ 5 ] = "" ;
char buffer[ 80 ] = "" ;
year = date.substr ( date.find ( "/" ) + 1 ,date.length ( ) ) ;
strcpy ( buffer, year.c_str ( ) ) ;
strcpy ( buffer, date.c_str ( ) ) ;
strcpy ( day, strtok ( buffer,"/" ) ) ;
strcpy ( buffer, date.c_str ( ) ) ;
strcpy ( year, strrchr ( date.c_str ( ) , '/' ) ) ;
for ( int i = 0 ; i < 5 ; i++ )
{
year[ i] = year[ i + 1 ] ;
}
strcpy ( buffer, date.c_str ( ) ) ;
strcpy ( buffer, ( ( strrchr ( date.c_str ( ) ,'/' ) ) ,( strchr ( date.c_str ( ) , '/' ) + 1 ) ) ) ;
strcpy ( month, strtok ( buffer,"/" ) ) ;
cout << "DAY: " << day << endl;
cout << "MONTH: " << month << endl;
cout << "YEAR: " << year << endl;
cout << "--------------------------------" << endl;
}
I2luY2x1ZGUgPGNjdHlwZT4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8Y2N0eXBlPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8Y3RpbWU+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnZvaWQgZGF0ZVBhcnNlKHN0cmluZyk7CmludCBtYWluKCk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ZmZlciwiLyIpKTsKICAgIGNvdXQgPDwgIkRBWTogIiA8PCBkYXkgPDwgZW5kbDsKICAgIGNvdXQgPDwgIk1PTlRIOiAiIDw8IG1vbnRoIDw8IGVuZGw7CiAgICBjb3V0IDw8ICJZRUFSOiAiIDw8IHllYXIgPDwgZW5kbDsKICAgIGNvdXQgPDwgIi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tIiA8PCBlbmRsOwp9
compilation info
prog.cpp: In function ‘void dateParse(std::string)’:
prog.cpp:31:9: error: incompatible types in assignment of ‘std::basic_string<char>’ to ‘char [5]’
year = date.substr(date.find("/")+1,date.length());
^
prog.cpp:32:24: error: request for member ‘c_str’ in ‘year’, which is of non-class type ‘char [5]’
strcpy(buffer, year.c_str());
^
stdout