I have an assignment that uses the strtok function to read two times, then outputs the first and last hours and minutes from each time (by the way this is only a small section of my assignment)
The problem that I have is getting the first times minutes to be displayed.
I have tried all ways I can think of to get the first times minutes, but I have spent hours trying to figure it out :( I just hope someone can show me how I could do this or go about doing this
All my other times work perfectly
I am extremely new to C++ and I am not allowed to use pointers (not that I understand how to use them anyway)
Here is my code so far:
Code:
#include<iostream>
#include<conio>
#pragma hdrstop
using namespace std;
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
char firsttime[8];
char lasttime[8];
int firsthour = 0;
int firstmins = 0;
int lasthour = 0;
int lastmin = 0;
cout << "Enter first time: "; //firsttime input
cin.getline( firsttime, 8 );
cout << "Enter second time: "; //lasttime input
cin.getline( lasttime, 8 );
firsthour = atoi( strtok( firsttime, ":" ) );
lasthour = atoi( strtok( lasttime, ":" ) );
firstmins = atoi( strtok( ?????? what do i put in here ???? ) );
lastmins = atoi(strtok( NULL, lasttime ) ); // this part works fine
cout << firsthour << "\n";
cout << lasthour << "\n";
cout << firstmins << "\n";
cout << lastmins << "\n";
getch();
return 0;
}