From 8a103256dfa677b21425ce15a33c1fdf2c7810e7 Mon Sep 17 00:00:00 2001 From: "David Vereb (Home)" Date: Fri, 29 Mar 2019 18:35:22 -0500 Subject: [PATCH] Refactored to take advantage of printw's printf capabilities. --- main.cpp | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/main.cpp b/main.cpp index dd95d55..a2a0710 100644 --- a/main.cpp +++ b/main.cpp @@ -6,16 +6,9 @@ int main(int argc, char *argv[]) { initscr(); - if(argc != 2) - { - printw("You must supply a filename as the only parameter."); - refresh(); - getch(); - endwin(); - return 1; - } - - std::string param = std::string(argv[1]); + std::string param = "-h"; // default to usage + if(argc == 2) + param = std::string(argv[1]); if(param == "--help" || param == "-h") { printw("Supply the filename as the only parameter.\n"); @@ -30,20 +23,17 @@ int main(int argc, char *argv[]) std::ifstream ifs(argv[1]); if(!ifs.is_open()) { - printw("Permission Denied."); + printw("ERROR: File \"%s\" Not Found.", param.c_str()); refresh(); getch(); endwin(); - return 2; + return 1; } noecho(); cbreak(); - printw("New file, \""); - printw(argv[1]); - printw("\".\n"); - printw("\n"); + printw("New file, \"%s\".\n\n", param.c_str()); refresh(); getch();