일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- C++ 언어 #핵심정리
- C언어 #핵심정리
- C언어 # 부록
- Hacking #Baic
- shell_script
- C언어 #부록
- MySQL #핵심정리
- C++ 언어 # 핵심정리
- PHP #핵심정리
- Bandit
- HTML #핵심정리
- C++ 언어 # 핵심 정리
- C언어 # 핵심 정리
- Today
- Total
cCcode
[부록] 문자열 함수들을 이용한 간단한 프로그램(완성본) 본문
#include <Windows.h>
#include <stdio.h>
#include <string.h>
typedef struct {
char name[30];
int average_score;
char rank;
}Data_Base;
void PRINT_TITLE();
int main()
{
Data_Base d1;
int input_one;
int input_two;
char input_three[30];
char input_three_char;
int input_three_num = 0;
strcpy_s(d1.name, 7, "cCcode");
d1.average_score = 50;
d1.rank = 'B';
outset:
PRINT_TITLE();
printf(" Helper : If you want continue, press ENTER.\n");
Sleep(3000);
printf(" ");
input_one = getchar();
if (input_one == '\n')
{
system("cls");
PRINT_TITLE();
}
else
{
move:
printf("\n");
printf(" Helper : Wrong input\n");
printf(" Helper : Force ture off Program.\n");
Sleep(1500);
for (int i = 0; i < 3; i++)
{
system("cls");
if (i == 0)
printf(" Turn off the Program.");
else if (i == 1)
printf(" Turn off the Program. .");
else
printf(" Turn off the Program. . .");
Sleep(1500);
}
system("cls");
printf(" T H A N K Y O U");
Sleep(2000);
system("cls");
printf(" Made in cCcode\n\n");
return 0;
}
printf(" 1) Modifying\n");
printf(" 2) Showing\n\n");
printf("INPUT : ");
scanf_s("%d", &input_two);
if (input_two == 1)
{
Sleep(2000);
system("cls");
PRINT_TITLE();
printf(" 1 - Name : %s\n", d1.name);
printf(" 2 - score : %d\n", d1.average_score);
printf(" 3 - rank : %c\n", d1.rank);
printf("\nHelper : Please enter the sentence you want to correct.");
printf("\nHelper : you should to case sensitive.\n\n");
printf("INPUT : ");
scanf_s("%s", input_three, (unsigned char)sizeof(input_three));
input_three[6] = '\0';
if (strcmp(input_three, "Name") == 0)
{
printf("\n\nHelper : enter the correction value\n\n");
printf("INPUT : ");
rewind(stdin);
scanf_s("%[^\n]s", input_three, (unsigned char)sizeof(input_three));
strcpy_s(d1.name, sizeof(input_three), input_three);
printf("\n\nHelper : Restart Program.");
Sleep(2000);
system("cls");
rewind(stdin);
goto outset;
}
else if (strcmp(input_three, "score") == 0)
{
printf("\n\nHelper : enter the correction value\n\n");
printf("INPUT : ");
scanf_s("%d", &input_three_num);
d1.average_score = input_three_num;
printf("\n\nHelper : Restart Program.");
Sleep(2000);
system("cls");
rewind(stdin);
goto outset;
}
else if (strcmp(input_three, "rank") == 0)
{
printf("\n\nHelper : enter the correction value\n\n");
printf("INPUT : ");
rewind(stdin);
scanf_s("%c", &input_three_char, (unsigned char)sizeof(input_three));
d1.rank = input_three_char;
printf("\n\nHelper : Restart Program.");
Sleep(2000);
system("cls");
rewind(stdin);
goto outset;
}
else goto move;
}
else if (input_two == 2)
{
Sleep(2000);
system("cls");
PRINT_TITLE();
printf(" 1 - Name : %s\n", d1.name);
printf(" 2 - score : %d\n", d1.average_score);
printf(" 3 - rank : %c\n", d1.rank);
}
else goto move;
return 0;
}
void PRINT_TITLE()
{
printf("+~~~~~~~~~~~~~~~~~~ Data Base Program ~~~~~~~~~~~~~~~~~~+\n\n");
}
우선 프로그램을 처음 실행시키시면 다음과 같은 문구가 뜰텐데요. 반드시 Enter 를 눌러주세요. Enter 가 아닌 경우 프로그램을 강제 종료하게 만들었습니다.
Enter 을 제대로 입력하시면 다음 화면이 뜰텐데요.
저희는 1번 Modifying 즉, 수정을 선택해야 합니다. 왜냐하면 2번 Showing은 수정 후 값을 확인하는 용도로 만들어 해당 구조체들의 값을 확인하고 바로 프로그램을 종료하기 때문입니다.
이때는 수정할 항목의 문장을 그대로 적어야 하며, 대소문자 구분은 필수입니다. 사실 제가 따로 분기문을 만들었다면 상관없겠지만.. 귀찮아서..ㅎㅎ
그 다음엔 수정 값을 입력해줘야 하는데 수정 값은 해당 요소와 같은 타입, (ex) score의 경우 : 10)으로 입력해야 합니다.
이제 그전에 선택하지 않았던 2번 Showing을 입력해 제대로 수정되었는지 확인해봅시다.
예에~ 값이 정상적으로 수정된 걸 확인하실 수 있습니다.
ps. 영어 공부를 할 겸 대부분의 내용을 영어로 작성했는데 조금 불편하셨나요...?
제가 이 프로그램을 만든 목적은 여러분들이 문자열 함수와 구조체 사용에 익숙해지도록 하는 데 있습니다. 따라서 단지 코드를 복사해서 사용하는 그치지 않고, 값과 코드 그 자체를 수정해가며 실력이 향상되셨으면 합니다.
이상 cCcode 입니다.
'C Language Basic' 카테고리의 다른 글
C Language [핵심정리] - 28 (0) | 2021.06.15 |
---|---|
C Language [핵심정리] - 27(수정) (0) | 2021.06.11 |
C Language [핵심정리] - 25 (0) | 2021.06.08 |
C Language [핵심정리] - 24 (0) | 2021.06.06 |
C Language [핵심정리] - 23 (0) | 2021.06.04 |