int main()
{
int d;
char destination[5];
char departure_time[6];
FILE* fp = fopen("/home/cs2015/shuttle.txt", "r");
while( fscanf(fp, "%d %s %s", &d, destination, departure_time) != EOF )
{
cout << d << destination << departure_time << endl;
}
fclose(fp);
}
#include <iostream>
#include <ctime>
using std::cout;
using std::endl;
int main(int argc, char* argv[])
{
char now[] = "00:00";
time_t rawtime;
time( &rawtime );
struct tm *timeinfo = localtime( &rawtime );
strftime(now, 5, "%H:%M", timeinfo);
if (argc == 2)
strcpy(now, argv[1]);
cout << "Now is " << now << endl;
return 0;
}
When you run "argv.exe", you get the current time.
Now is 17:44
The shuttle bus leaves for Puli at 18:10
The shuttle bus leaves for NCNU at 18:10
At 07:00, you may consider:
The shuttle bus leaves for Puli at 08:10
The shuttle bus leaves for NCNU at 07:30
At 14:00, you may consider:
The shuttle bus leaves for Puli at 15:10
The shuttle bus leaves for NCNU at 15:40
At 14:00, you may consider:
The shuttle bus leaves for Puli at 14:10
The shuttle bus leaves for NCNU at 14:40
At 23:00, you may consider:
The last shuttle bus bound for Puli has left.
The last shuttle bus bound for NCNU has left.