/* This is the exact same program as move_filenames_2.cpp, but now I have defined prototypes for move_2019() and move_photo(). The compiler is much happier now. */ #include #include #include #include using namespace std; void move_2019(string line); void move_photo(string line); int main() { string l; while (getline(cin, l)) { if (l.substr(0, 4) == "2019") { move_2019(l); } else { move_photo(l); } } return 0; } void move_2019(string line) { size_t i; i = line.find(' '); if (i == string::npos) { fprintf(stderr, "move_2019() - the line of text has no space.\n"); exit(1); } printf("mv '%s'", line.c_str()); line[i] = '-'; printf(" %s\n", line.c_str()); } void move_photo(string line) { string p, month, comma, ampm; int day, hour, minute, second; int m; istringstream ss; ss.str(line); if (ss >> p >> month >> day >> comma >> hour >> minute >> second >> ampm) { m = (month == "Jul") ? 7 : 8; if (ampm.substr(0, 2) == "PM") hour += 12; printf("mv '%s' 2019-%02d-%02d-%02d.%02d.%02d.jpg\n", line.c_str(), m, day, hour, minute, second); } else { fprintf(stderr, "move_2019() - line in the wrong format.\n"); exit(1); } }