Contents
- 1. /startLine
- 2.
- 2.1. 1-, (2012-03-21)
- 2.2. 1- (2012-03-22)
- 2.3. 2- (2012-03-26)
- 2.4. 3- (2012-3-28)
- 2.5. 3-, (2012-3-28)
- 2.6. 4- (2012-4-2)
- 2.7. 4- (2012-4-3)
- 2.8. 5- (2012-4-4)
- 2.9. 5- (2012-4-5)
- 2.10. 4- (2012-4-5)
- 2.11. 6- (2012-4-9) + 7- (2012-4-9)
- 2.12. 8 (2012-5-1) - ,
- 2.13. 9(2012-5-9) - ,
- 2.14. 10(2012-5-22) - ,
- 2.15. 11(2012-5-23) - ,
- 2.16. 12(2012-7-19)
- 2.17. 13(2012-7-20)
- 2.18. 2012-7-30
- 2.19. 2012-8-2
2.3.2. ¶
- 복문 - 복문 . 듯
int main() { int num1 , num2 = 1, num3, num4 = 2; printf(" 를 \n"); scanf("%d", &num1); num3 = num1 - 1; while(num2 <= num1){ while(num3 < num1){ printf("*"); num3++; } printf("\n"); num3 = num3 - num4; num2 = num2 + 1; num4++; } return 0; }
2.3.3. ¶
- - 문 대 내 배 느낌 마 문는 러 는 문 더 는 .
- 민 - 문 대 (if문, switch.. for...) 몇몇 문 들(switch break, 복문 료등..) 리 면 보 부들 대 명( 밍, python, 른 c들) 번 보 매럽 번 대 는데 1:1 런 . 리 보 부 문 는 보 . 내들 C를 배 들 는데 if문 for문 문 른 놀랐. printf, scanf 리 c 본문 .
2.4.3. ¶
- (if문, 복문) 복 배 대 보. 리 번 내 를 만는 , 를 는 등. 는 를 는 만 면 . 리 는 만 문 부 른는 . 른 는데 내 변 scope 내부 등 대 문 . 리 printf문 를 보는데 . 는 를 데 를 는 더 바 를 민. 를 모르. - 민
-
- 배, 배 는
- 란? , 만는
- 를 받 대
- 봐 ......? -
2.5.3. ¶
- , 대 . swap 를 만들 보 문 대 를 . 를 대 복는 대 들. 민 부 를 떤 밍 는는데, 무 call-by-value 문 대 를 면 를 내는 . 는 림 램 메모리 떻 는 대 명 변를 는 방(call-by-reference) . 리 malloc 메모리를 는 배 대 루. 느낌는 는 느 내 는 느낌 . 대 메모리 를 림 는데, 를 는 문 등 . 는 C 런런 부 문 많는데 무 C 부 미 는 . 리 무 를 더 는 . - 민
- 를 swap , 변. 리 malloc 더 는 . malloc 램 보 . -
- , 변 , malloc , fflush() , getchar() , 메모리 heap stack , (int)a *(*(int a)) , OS (DWORD 를 따. 32bit/64bit),
봐 - 디, 변 , 복. -
2.6.3. ¶
- 번 swap 대 복 swap 문 대 보. 리 념 를 는 방 . 느끼는 만 call-by-value 문 리 를 들 는 느끼 는 . 리 념 명 . 는 대 부 럼 malloc 부 는데 대 문 른 부 루 보 늦. 는 는 만 는 본. 리 목는 목 무 는 . 들 는 만 목만 루 C 러 . - 민
- 대 대략 념 - 복만 면 듯 .
.
메모리 + - 변 변 + ...데 림 명 . -
2.7.3. ¶
- 배 받 뒤 - 배 받 뒤는 .
// void reverseArr(int **arr, int arrLen); // int arr[10]; reverseArr(&arr, 10);
2.8.2. ¶
- 변 면 떻 는(malloc ) 메모리 (free ) 대 를 . 리 배 대 를 는데, 배 메모리를 는는 변 는 . 는 변(배)를 받는 를 만는 배, 배 받 는 를 리 는 를 . - 민
- malloc = 배는 메모리, 변 따 따 는 메모리(변?)
Pointer 배 = .
배() 받는 = , |
념들. -
2.10.2. ¶
- 맞 를 . 목는 ( ) 는 는데, 모랐. 대는 번 더 루 들 모 더 루는 마 . - 민
- 동(malloc) , , typedef 대 념리를 대 메모리 림 . , 방 대 대 많 를 . 배 를 보 대 를 . -
2.11.2. ¶
- 를 를 .
- 모 , 모 린 말 . ;;;; 는 문 대 룰 는데 대 를 면 많 른 방 러. 를 () () 말 는데 부 떨는 . 런 부 보 면 . ( 리 램 등) , 만들 보 는 . 봐. - 민
2.12.2. ¶
- : 를 만는 . 리. 복.
봐 : reverse(number) - 배 뒤는
: 문 ...미... , 대 높 듯 . C러 많 느 . 보람 느. -
- 문 대 복 ' 밍' 대 루. 복 뒤 밍 부. 내 램 미() 는 를 데를 만 내물 는 방. 내 루 내 는 부 민 많 는데, 는 . 는 르 머 대 봐 . - 민
2.12.3. ¶
- 를 만듭.
- reverse 만들 는 .
내 면 를 만는 는 부
를 만들 . 더 들 는 .
// 를 면 를 뒤 돌. // 123 면 321 리. 100 면 1 리. 120 면 21 리. int reverse(int number);
2.13.3. - 린더 만들 ¶
- Calender.h - 만들 들. 더 .
// 는 . void printCalender(int nameOfDay, int year, int month); // (nameOfDay) 마막 를 받 1~endDayOfMonth . void printDate(int nameOfDay, int endDayOfMonth); // 1 부 빈 만 ('\t') . void printFirstTab(int nameOfDay); // 머리 부(, , , ) . void printHeader(int year, int month); // . int calculateNameOfNextMonthFirstDay(int nameOfDay, int year, int month); // 마막 . int calculateNameOfLastDay(int nameOfDay, int year, int month); // . bool isLeapYear(int year); // 마막 를 . // switch-case문 루 며, 2 대는 를 . int endDayOfMonth(int year, int month); // 를 받 문 . (ex. 0-"Sun", 1-"Mon" ...) // switch-case문 루 . char *printMonthName(int i);
- main.cpp
#include <stdio.h> #include "Calender.h" int main(int argc, char *args[]) { // year (nameOfDay) 받는 부. int year = 0, nameOfDay = 0; printf("Enter the year : "); scanf("%d", &year); printf("Enter the name of day(0:sun ~ 6:sat) : "); scanf("%d", &nameOfDay); // 1~12 는 부. for ( int month = 1; month <= 12; month++ ) { printCalender(nameOfDay, year, month); nameOfDay = calculateNameOfNextMonthFirstDay(nameOfDay, year, month); } return 0; }
- sample output - 1부 12. 면 ('\t') 면 됩.
January, 2012 ------------------------------------------------- Sun Mon Tue Wed Thu Fri Sat 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
2.13.4. ¶
- strcat(str1, str2)를 str1 린는데 는.
People p; strcat 문 . p를 (People p = {0};) 면
p.name 는 . strcat 면 p.name 부(p.name99 부) "동" 내 붙.
런 는 p를 memset(p.name, 0, sizeof(char)*100); 는 방 .
#include <stdio.h> #include <string.h> typedef struct People{ char gender; int age; char name[100]; char real_name[100]; } People; int main() { char str1[100] = "abc"; char str2[100] = "aaa"; People p; strcat(p.name, "동"); strcat(str1, str2); printf("%s", str1); getchar(); return 0; }
2.14.1. 내 ¶
- 를 더 루 봤면 는 를 보 는
를 만 를 만들 봤.
- 대 는 램 만들 본는 .
리 addAccount() deleteAccount()는 .
#include <stdio.h> typedef struct Account { char *name; int money; } Account; typedef struct AccountArray { struct Account **accounts; int currentAccountNumber; int maxLength; // 배 는 를 리는 를 만들 면 . } AccountArray; Account *createAccount(char *name); // Account 끔 는 문 . AccountArray *createAccountArray(int maxLength); void addAccount(AccountArray *accountArray, char *name); bool isFull(AccountArray *accountArray); // 배 면 떻 면 ?????? AccountArray *extendArray(AccountArray *before); // 배 . void deleteAccount(AccountArray *accountArray, char *name); // 배 ? 멍만 뻥 뚫면 ? void deposit(AccountArray *accountArray, char *name, int money); // accountArray 내부 . void withdraw(AccountArray *accountArray, char *name, int money); void addAccountMenu(); void deleteAccountMenu(); void depositMenu(); void withdrawMenu();
main.cpp
#include <stdio.h> #include "Account.h" int main(int argc, char *argv[]) { int select = 0; // 변들 . while ( true ) { printf("select menu : "); printf("1: \n"); printf("2: \n"); printf("3: \n"); printf("4: \n"); scanf("%d", &select); switch ( select ) { case 1: addAccountMenu(); break; case 2: deleteAccountMenu(); break; case 3: depositMenu(); break; case 4: withdrawMenu(); break; default: break; } } return 0; }
2.15.1. 내 ¶
////////////////////////////////////// 본 , 본 + char a; // a ? 1. 메모리 a 보. a = ?? // 보. int b; // b ? 1. 메모리 b 보. b = ?? // 보. char c[10]; // c ?, 1. 동 0 보., 2. 복문 마 보., 3. c[0] ? char *d; // d ? char 10 량 배 동 보. // c d를 메모리 보. . ??? // []를 c 번 보. ??? // 능 방 d 번 보. ??? // 능 방 c 번 보. // array[0] == *(array + 0) 배 대 는 는 동 . //////////////////////////////////////// , + Person p; // p ? 1. 메모리 p 모 보. ??? // p 내물 보. Person pArr[10]; // pArr ? 1. 메모리 pArr 모 보. ??? // pArr 0번 내물 보 Person *p2; // p2 ? 1. 메모리 p2 모 보. ??? // p2 보. ??? // p2 내물 보. Person *ppa[10] // ppa ? 1. 메모리 ppa 모 보., 2. ppa[0] ? 3. ppa[0] 보. 4. ppa[0] 내물 보. Person **ppb // ppb ? 1. 메모리 ppb 모 보., 2. ppb[0] ? 3. ppb[0] 보., 4. ppb[0] 내물 보.
2.16.1. 내 ¶
- AccountArray 들 만들.
- createAccount(char *name) Account *를 는.
Account makeAccount(char *name) { Account account; account.money = 0; account.name = (char *)malloc(sizeof(char) * (strlen(name)+1)); strcpy(account.name, name); return account; } void addMoney(Account account, int money) { account.money += money; }냥 Account를 만 들 보면 를 .
Account를 냥 면 call-by-value Account 복본 money를 문
본 Account는 무런 변 .
- extendArray 등 불.
2.17.1. 내 ¶
- 복.
- LinkedList 념.
- ArrayList(Array) LinkedList .
- LinkedList 들 는 부들( ).
- LinkedList.h
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef int Data; typedef struct Node { Data data; Node *nextNode; } Node; typedef struct LinkedList { int length; Node *headNode; } LinkedList; LinkedList *createList(); Node *createNode(Data data); void deleteList(LinkedList *linkedList); // LinkedList . void addData(LinkedList *linkedList, Data data); // LinkedList 맨 뒤 Data를 Node . void removeData(LinkedList *linkedList, Data data); // 는 Data를 Node . Node *getData(LinkedList *linkedList, int position); // 는 index를 Node를 . void clearList(LinkedList *linkedList); // LinkedList Node들 . void printList(LinkedLIst *linkedList);
2.17.2. 들 ¶
#include "LL.h" LinkedList *createList(){ LinkedList *res; res = (LinkedList *)malloc( sizeof(LinkedList) ); (*res).headNode = NULL; (*res).length = 0; return res; } Node *createNode(Data data){ Node *res; res = (Node *)malloc( sizeof(Node) ); (*res).data = 0; (*res).nextNode = NULL; return res; } void deleteList(LinkedList *linkedList){ clearList(linkedList); free(linkedList); } void addData(LinkedList *linkedList, Data data){ Node *node = createNode( data ); Node *temp = linkedList->headNode; for(;temp->nextNode != NULL;){ temp = temp->nextNode; } temp->nextNode = node; } void removeData(LinkedList *linkedList, Data data){ int onoff = 0; //for duty of switch Node *remove = linkedList->headNode; if( remove->data == data ){ free( remove ); //If the object is headNode onoff = 1; } if( onoff == 0 && remove->nextNode->data == data ){ free( remove->nextNode ); //If the object is the nextNode of headNode onoff = 1; } for(; onoff == 0 && remove->nextNode->data != data;){ //... remove = remove->nextNode; } remove->nextNode = remove->nextNode->nextNode; // remove remove-n remove-n-n free(remove->nextNode); // remove ~ remove-n-n , free remove-n } Node *getData(LinkedList *linkedList, int position){ Node *get = linkedList->headNode; for( int i = 0 ; i < position ; i++ ){ get = get->nextNode; } return get; } void clearList(LinkedList *linkedList) { Node *now = (*linkedList).headNode; Node *next; for( ; (*now).nextNode != NULL ; ){ //now 는동 복 next = (*now).nextNode; //next는 now free( now ); //now를 free now = next; //next를 now } free( now ); //now를 free } int lengthOf(LinkedList *linkedList){ int length = 0; Node *temp = linkedList->headNode; for( ; temp->nextNode != NULL ; length++ ){ temp = temp->nextNode; } return length; } void printList(LinkedList *linkedList){ Node *temp = linkedList->headNode; for( ; temp->nextNode != NULL ; ){ printf("%d\t", temp->data); temp = temp->nextNode; } printf("\n"); }
2.18.1. ¶
int main() { Stack *stack = createStack(); assert(stack->elementNumber == 0); assert(stack->head == NULL); push(stack, 10); assert(stack->elementNumber == 1); assert(peek(stack)->data == 10); push(stack, 20); assert(stack->elementNumber == 2); assert(peek(stack)->data == 20); assert(pop(stack)->data == 20); assert(stack->elementNumber == 1); Node *result = pop(stack); assert(result->data == 10); assert(isEmpty(stack)); return 0; }