#include #include #include #include #include using namespace std; #define welcomemsg "Welcome to Grim Message Keeper!" #define BLOCK_SIZE 1024 char* msgfile = ".grimsg"; void CountMessages() { // This assumes that each mesage takes only one line (in msgfile) // and that there are no empty lines int counter = 0; string line; ifstream msglist; msglist.open(msgfile, std::ios::binary); // open in binary mode if (! msglist) { cout << "grim_counter error: Unable to open " << msgfile << "\n"; exit(1); } while(getline(msglist,line)) //each time an entire line is read { // into line counter is incremented ++counter; } cout << "\nYou have " << counter << " new messages\n"; // There is no need to prompt user to type grim if there are // messages to view. if(counter != 0) { cout << "Type \"grim\" to see messages\n\n"; } } int main(int argc, char* argv[]) { for (int c=0; c < argc;++c) { if(!strcmp(argv[c],"-c") || !strcmp(argv[c],"--count")) { CountMessages(); exit(0); } } cout << welcomemsg << endl; return 0; }