.---+- include -+- tools -+- color.h
| +- hint.h <---
|
+- src -+- tools -+- color.c
| +- hint.c <---
|
+- main.c
// hint.h
#ifndef _HINT_H_
#define _HINT_H_
void welcomeMessage();
void successMessage();
void failureMessage();
void illegalMessage();
void loadingMessage();
void exitingMessage();
void invalidMessage();
#endif
// hint.c
#include "tools/hint.h"
#include "tools/color.h"
#include <stdio.h>
// all kinds of visual hints
static const char* BANNER = "\
\t__ ___ _ __ __ _ _ _\n\
\t\\ \\ / / | | | | \\/ | | | | | | |\n\
\t \\ \\ /\\ / /| |__ __ _| | ___ | \\ / | __ _ _ __| | _____| |_ | |\n\
\t \\ \\/ \\/ / | '_ \\ / _` | |/ _ \\ | |\\/| |/ _` | '__| |/ / _ \\ __| | |\n\
\t \\ /\\ / | | | | (_| | | __/ | | | | (_| | | | < __/ |_ |_|\n\
\t \\/ \\/ |_| |_|\\__,_|_|\\___| |_| |_|\\__,_|_| |_|\\_\\___|\\__| (_)\n\
";
static const char* SUCCESS = "\t\t*** Operation Successful! ***";
static const char* FAILURE = "\t\t*** Operation Failed! ***";
static const char* ILLEGAL = "\t\t*** Illegal Input! ***";
static const char* LOADING = "\t\t*** Loading ... ***";
static const char* EXITING = "\t\t*** Exiting ... ***";
static const char* INVALID = "\
\t _____ _ _ _ _\n\
\t |_ _| | | (_) | | | |\n\
\t | | _ __ __ __ __ _ | | _ __| | | |\n\
\t | | | '_ \\ \\ \\ / / / _` | | | | | / _` | | |\n\
\t _| |_ | | | | \\ V / | (_| | | | | | | (_| | |_|\n\
\t |_____| |_| |_| \\_/ \\__,_| |_| |_| \\__,_| (_)\n\
";
void welcomeMessage() {
printf("\n%s%sWelcome to%s\n", BOLD, FRONT_RED, RESET);
printf("%s%s%s%s\n", FRONT_BLUE, BOLD, BANNER, RESET);
printf("%sThis is WinterCode Project for C-Beginners.%s\n\n", FRONT_PURPLR, RESET);
}
void successMessage() { printf("\n%s%s%s\n\n", FRONT_GREEN, SUCCESS, RESET); }
void failureMessage() { printf("\n%s%s%s\a\n\n", FRONT_RED, FAILURE, RESET); }
void illegalMessage() { printf("\n%s%s%s\a\n\n", FRONT_RED, ILLEGAL, RESET); }
void loadingMessage() { printf("\n%s%s%s\n\n", FRONT_BLUE, LOADING, RESET); }
void exitingMessage() { printf("\n%s%s%s\n\n", FRONT_RED, EXITING, RESET); }
void invalidMessage() {
printf("\n%s%s%s\n\n", FRONT_RED, INVALID, RESET);
printf("\n%s%sThis Function is Waiting For you to Implement ...%s\n\n", \
FRONT_RED, BOLD, RESET);
}
上述设计涉及到了C语言中变量作用域以及生存期的相关知识,如果这部分知识点还不够清晰的话,可能需要先找一些相关教程复习一下,因为在我的整个设计当中会经常用到C语言的这些特性。在之后的教程中,如非必要,我将不再解释该知识点。
到此,我们封装了整个程序中所需要的所有提示信息(除了菜单,因为菜单具有除了提示以外的其他功能,所以没有封装在hint里面)。
其实在实际开发过程中,不会一下子就把这个模块写完的,而是在过程中不断迸出新的需求,然后往这个模块里面添加功能和接口,最终形成了你现在看到的这个模块。