모두의 코드
모두의 코드

총 42 개의 강의로 준비된 씹어먹는 C 언어 강좌를 통해 C 언어의 처음부터 끝까지 배우실 수 있습니다! 특히 악명 높은 C 언어의 포인터나, 어려운 개념들을 충실히 짚고 넘어갑니다.

이 강좌는 2010년에 완결되었지만, 지속적으로 개선 및 보완하고 있습니다.

C 언어 문법을 아시는 분들이라면, 씹어먹는 C++ 강좌를 통해 C++ 기초 부터 최근의 C++ 17 까지 모든 내용을 배우실 수 있습니다. C 언어와 C++ 의 기본적인 문법이 비슷하기 때문에, C 언어를 어느 정도 아는 독자를 가정하여 쓰여져 있습니다.

이 강좌는 2020년에 완결되었고 총 50 개의 강좌가 준비되어 있습니다.

사이트 내에서 검색 하기
C 언어 레퍼런스
표준 입출력 라이브러리 stdio.h
문자열 관련 라이브러리 string.h
시간 관련 라이브러리 time.h
C ++ 레퍼런스
문자열 라이브러리 string
알고리즘 라이브러리 algorithm
최근 댓글
#include <stdio.h> void strcopy(const char* from, char* to, const int len); int starts_with(const char* s1, const char* s2); int action(char (*books)[64], char (**bookptr)[64]); void read_until(const char* s, const int len); int main() { printf_s("도서관에 오신 것을 환영합니다!\n"); printf_s("help를 입력하면 명령어 목록을 볼 수 있습니다.\n"); // book의 첫 번째 char: 대출 가능 여부(0: 대출 불가능, 1: 대출 가능) char books[100][64] = {}; char (*book)[64] = books; while (action(books, &book)); } int action(char (*books)[64], char (**bookptr)[64]) { const char cancel[3] = "~~"; const char cleaner[16] = {}; const char help[] = "사용 가능한 명령어는 다음과 같습니다:" "\n\thelp: 도움말" "\n\tregister: 책 등록" "\n\tborrow: 책 대출" "\n\treturn: 책 반납" "\n\tbooks: 책 리스트" "\n\tfind: 책 정보" "\n\tstop: 프로그램 종료\n"; char input[64] = {}; printf_s("도서관> "); scanf_s("%s", &input, 16); if (starts_with(input, "help")) { printf_s(help); return 1; } else if (starts_with(input, "register")) { if (*bookptr - books < 100) // 책을 넣을 곳이 더 있다면 { printf_s("책의 이름을 입력해 주십시오. '~~'를 입력하여 취소하십시오.\n도서관> "); strcopy(cleaner, input, 16); *input = 1; scanf_s("%s", &input[1], 31); if (starts_with(&input[1], cancel)) { return 1; } printf_s("입력: \""); read_until(&input[1], 31); printf_s("\"\n"); printf_s("책의 저자를 입력해 주십시오\n도서관> "); scanf_s("%s", &input[32], 16); if (starts_with(&input[32], cancel)) { return 1; } printf_s("입력: \""); read_until(&input[32], 16); printf_s("\"\n"); printf_s("책의 출판사를 입력해 주십시오\n도서관> "); scanf_s("%s", &input[48], 16); if (starts_with(&input[48], cancel)) { return 1; } printf_s("입력: \""); read_until(&input[48], 16); printf_s("\"\n"); strcopy(input, *((*bookptr)++), 64); printf_s("\n도서관에 책이 등록되었습니다! (%d번)\n", *bookptr - books - 1); } else { printf_s("죄송하지만 도서관이 가득 차서 더 이상 책을 추가할 수 없어요.\n"); } } else if (starts_with(input, "borrow")) { int i; printf_s("대출할 책의 번호를 입력해 주십시오. '~~'를 입력하여 취소하십시오.\n도서관> "); scanf_s("%d", &i); char (*book)[64] = &books[i]; if (!*book[1]) { printf_s("%d번 책을 찾을 수 없습니다.\n", i); return 1; } printf_s("%d번 책 \"", i); read_until(*book + 1, 31); // 대출 가능 if (**book) { **book = 0; printf_s("\"을 대출했습니다.\n"); } else { printf_s("\"은 이미 대출중입니다.\n"); } } else if (starts_with(input, "return")) { int i; printf_s("반납할 책의 번호를 입력해 주십시오. '~~'를 입력하여 취소하십시오.\n도서관> "); scanf_s("%d", &i); char (*book)[64] = &books[i]; if (!*book[1]) { printf_s("%d번 책을 찾을 수 없습니다.\n", i); return 1; } printf_s("%d번 책 \"", i); read_until(*book + 1, 31); //반납 가능 if (!**book) { **book = 1; printf_s("\"을 반납했습니다.\n"); } else { printf_s("\"을 대출하고 있지 않습니다.\n"); } } else if (starts_with(input, "books")) { for (int i = 0; i < 100; i++) { char (*book)[64] = &books[i]; printf_s("%d번: 책 이름: \"", i); read_until(*book + 1, 31); printf_s("\", 저자: \""); read_until(*book + 32, 16); printf_s("\", 출판사: \""); read_until(*book + 48, 16); printf_s("\"\n"); } } else if (starts_with(input, "find")) { int i; printf_s("몇 번 책의 정보를 불러오시겠습니까?\n도서관> "); scanf_s("%d", &i); char (*book)[64] = &books[i]; if (!*book[1]) { printf_s("%d번 책을 찾을 수 없습니다.\n", i); return 1; } printf_s("%d번 책:\n\t책 이름: \"", i); read_until(*book + 1, 31); printf_s("\"\n\t저자: \""); read_until(*book + 32, 16); printf_s("\"\n\t출판사: \""); read_until(*book + 48, 16); printf_s("\"\n"); printf_s("이 책을 대출/반납하시겠습니까? 'borrow'(대출) 또는 'return'(반납)을 입력하십시오. 아니라면 아무 문자나 입력하십시오.\n"); strcopy(cleaner, input, 16); scanf_s("%s", &input); if (starts_with(input, "borrow")) { if (**book) { **book = 0; printf_s("대출되었습니다.\n"); } else { printf_s("이 책은 이미 대출 중입니다.\n"); } } else if (starts_with(input, "return")) { if (!**book) { **book = 1; printf_s("반납되었습니다.\n"); } else { printf_s("이 책을 대출하고 있지 않습니다.\n"); } } } else if (starts_with(input, "stop")) { printf_s("도서관을 이용해주셔서 감사합니다."); return 0; } else { printf_s("해당 명령어를 찾을 수 없습니다. 'help'를 입력해 명령어 목록을 볼 수 있습니다.\n"); } return 1; } void read_until(const char* s, const int len) { const char* max = s + len; while (s < max) { printf_s("%c", *(s++)); } } void strcopy(const char* from, char* to, const int len) { const char* max = from + len; for (; from < max; *(to++) = *(from++)); } int starts_with(const char* s1, const char* s2) { int result = 0; for (; *s2 != 0 && (result = (*s1 == *s2)); s1++, s2++); return result; }
Tomato 05.19