#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#define MAX_TODO 100
#define MAX_MEMO 10000
typedef struct Todo{
char text[200];
int completed;
} Todo;
Todo todos[MAX_TODO];
int todoCount = 0;
void showMenu();
void showCurrentTime();
//void showWeather();
//void showCPUUsage();
void writeMemo();
void readMemo();
void addTodo();
void showTodo();
void completeTodo();
int readInteger(const char* prompt);
void clearInputBuffer();
void clearInputBuffer(){
int ch;
while ((ch = getchar()) != '\n' && ch != EOF){
}
}
int readInteger(const char* prompt){
char input[100];
char* end;
long number;
printf("%s", prompt);
if(fgets(input, sizeof(input), stdin) == NULL){
return -1;
}
number = strtol(input, &end, 10);
if(end == input){
return -1;
}
while(*end == ' ' || *end == '\t'){
end++;
}
if(*end != '\n' && *end != '\0'){
return -1;
}
return (int)number;
}
//int main(){
// int menu;
//
// while(1){
// showMenu();
//
// menu = readInteger("선택 : ");
//
// switch(menu){
// case 1:
// showCurrentTime();
// break;
//
//// case 2:
//// showWeather();
//// break;
////
//// case 3:
//// showCPUUsage();
//// break;
//
// case 4:
// writeMemo();
// break;
//
// case 5:
// readMemo();
// break;
//
// case 6:
// addTodo();
// break;
//
// case 7:
// showTodo();
// break;
//
// case 8:
// completeTodo();
// break;
//
// case 0:
// printf("프로그램을 종료합니다.\n");
// return 0;
//
// default:
// printf("잘못된 메뉴입니다.\n");
// }
//
// printf("\n계속하려면 Enter를 누르세요...");
// getchar();
//
// system("cls");
// }
//
// return 0;
//}
void showMenu(){
printf("=========================\n");
printf(" PC Dashbord \n");
printf("=========================\n");
printf("1. 현재 시간\n");
printf("2. 날씨\n");
printf("3. CPU 사용률\n");
printf("4. 메모장 작성\n");
printf("5. 메모장 보기\n");
printf("6. Todo 추가\n");
printf("7. Todo 보기\n");
printf("8. Todo 완료\n");
printf("0. 종료\n");
printf("=========================\n");
}
void showCurrentTime(){
time_t now;
struct tm* localTime;
time(&now);
localTime = localtime(&now);
if(localTime == NULL){
printf("시간을 가져올 수 없습니다.\n");
return;
}
printf("\n현재 시간\n");
printf("=========================\n");
printf("%04d-%02d-%02d\n",
localTime->tm_year + 1900,
localTime->tm_mon + 1,
localTime->tm_mday);
printf("%02d:%02d:%02d\n",
localTime->tm_hour,
localTime->tm_min,
localTime->tm_sec);
}
//void showWeather(){
//
//}
//void showCPUUsage(){
//
//}
void writeMemo(){
char memo[MAX_MEMO];
FILE* fp;
printf("\n메모 작성\n");
printf("-------------------------\n");
printf("내용 : ");
if(fgets(memo, sizeof(memo), stdin) == NULL){
printf("입력에 실패했습니다.\n");
return;
}
fp = fopen("memo.txt", "w");
if(fp == NULL){
printf("파일을 열 수 없습니다.\n");
return;
}
fprintf(fp, "%s", memo);
fclose(fp);
printf("메모가 저장되었습니다.\n");
}
void readMemo(){
char buffer[500];
FILE* fp;
fp = fopen("memo.txt", "r");
if(fp == NULL){
printf("\n저장된 메모가 없습니다.\n");
return;
}
printf("\n메모\n");
printf("-------------------------\n");
while(fgets(buffer, sizeof(buffer), fp) != NULL){
printf("%s", buffer);
}
fclose(fp);
}
void addTodo(){
if(todoCount >= MAX_TODO){
printf("Todo를 더 이상 추가할 수 없습니다.\n");
return;
}
printf("\nTodo 추가\n");
printf("-------------------------\n");
printf("할 일 : ");
if(fgets(
todos[todoCount].text,
sizeof(todos[todoCount].text),
stdin) == NULL)
{
printf("입력에 실패했습니다.\n");
return;
}
todos[todoCount].text[
strcspn(todos[todoCount].text, "\n")
] = '\0';
todos[todoCount].completed = 0;
todoCount++;
printf("Todo가 추가되었습니다.");
}
void showTodo(){
int i;
printf("\nTodo List\n");
printf("-------------------------\n");
if(todoCount == 0){
printf("Todo가 없습니다.\n");
return;
}
for(i=0; i<todoCount; i++){
printf("%d. [%c] %s\n",
i + 1, todos[i].completed ? '0' : ' ',
todos[i].text);
}
}
void completeTodo(){
int number;
showTodo();
if(todoCount == 0){
return;
}
number = readInteger("\n완료할 Todo 번호 : ");
if(number < 1 || number > todoCount){
printf("잘못된 번호입니다.\n");
return;
}
todos[number - 1].completed = 1;
printf("Todo를 완료했습니다.\n");
}
To embed this project on your website, copy the following code and paste it into your website's HTML: