U E D R , A S I H C RSS

새싹교실/2012/start Line

1. /startLine

  • 간 :
  • :
  • : , , ,

2.1. 1-, (2012-03-21)

2.1.1.

  • .
  • wiki .
  • 0과 1 (ASCII code).
  • .
  • .
  • , (printf, scanf) (assert).
  • .

2.1.2.

  • .

2.1.3.

  • , 간 . 그 . . 경 ... . -
  • ㅋㅋㅋㅋㅋ -
  • ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ -

2.2. 1- (2012-03-22)

2.2.1.

  • .
  • (, ) .
  • (, call by value, call by reference, 구, )

2.2.2.

  • C .

2.2.3.

  • - 간 C 기, 기, , gcc . 과 간 . . .
  • - . .

2.3. 2- (2012-03-26)

2.3.1.

  • 1 .
  • .
  • (, ) (switch break , ).
  • .

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- (2012-3-28)

2.4.1.

  • .
  • / .
  • .
  • .
  • swap .

2.4.2.

  • 기.

2.4.3.

  • 간(if, ) . 그 , . 개 . 그 . scope . 그 printf . . . -

  • - ,
    - ? ,
    -
    - ......? -

2.5. 3-, (2012-3-28)

2.5.1.

  • , .
  • swap .
  • , .
  • malloc .
  • 계.

2.5.2.

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. 4- (2012-4-2)

2.6.1.

  • swap .
  • 과 값 (call-by-value).
  • , .
  • 과 기.

2.6.2.

  • C C 게까 . ... -

2.6.3.

  • swap 고 swap . 그 . call-by-value . 그고 개 고. 그 malloc 고 그 . 그 . 그 . C . -
  • - .
    .
    + - + 값 기... . -

2.7. 4- (2012-4-3)

2.7.2.


값과 *, & ( 고..) ..
malloc과 fflush
heap과 stack .

... ㅋㅋㅋㅋㅋㅋㅋㅋㅋ -

2.7.3.

  • 기 - .

//  
void reverseArr(int **arr, int arrLen);

//  
int arr[10];
reverseArr(&arr, 10);

2.8. 5- (2012-4-4)

2.8.1.

  • malloc .
  • 계.
  • .

2.8.2.

  • (malloc ) (free ) . 그 , 결국 고 값 . 그 () 고, . -
  • malloc = , (?)
    Pointer = 결국 .
    () = 값, 거 | 거
    . -

2.9. 5- (2012-4-5)

2.9.1.

  • .
  • , 구 (struct , ., typedef ).
  • (changeAge() ).
  • .

2.9.2.

  • 2. 고 그 typedef . 그고 구 . 그 typedef int* SOMETHING , . int **twoDim twoDim0 malloc . . 개 (*s).age . -> * . . . -
  • , 구 고, "#" . typedef .
.
  • 1. ... 그 C . 감ㅋ. -

2.10. 4- (2012-4-5)

2.10.1.

  • malloc .
  • , 구 , typedef .
  • .

2.10.2.

  • . ( )까 , . . -
  • (malloc)과 구, 구 , typedef 고 그 . , 구 . 고 그 . -

2.11. 6- (2012-4-9) + 7- (2012-4-9)

2.11.1.

  • .
  • .
  • (operation).
  • .
  • fopen() 급.

2.11.2.

  • 기간 . ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ
  • 간, . ;;;; 게 구 . (구)과 () . . ( ) , . . -

2.12. 8 (2012-5-1) - ,

2.12.1.

  • .
  • - .
  • () 개기.
  • 기.
  • (isPrime, isPalindromePrime ).

2.12.2.

  • : . . .
    : reverse(number) -
    : ...... 고, . C . . -
  • 과 ' ' . . () . 개 , 그 . . -

2.12.3.

  • .
  • 꼭 reverse .

    . .

//      .
// 123  321 . 100  1 . 120  21 .
int reverse(int number);

2.13. 9(2012-5-9) - ,

2.13.1.

  • callback, event driven과 기.
  • (char *) 기.
  • (str...).
  • winapi.co.kr

2.13.2.

  • Callback(winapi ) + winapi.co.kr
    5. + .
    ... 그 .
    . -
  • CallBack과 구 .
    .
    C function .
    . -
  • . 그 . , 그 . . 그 C char * 고 그 () . -

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. 10(2012-5-22) - ,

2.14.1.


  • .
  • .
    고 addAccount() deleteAccount() .

Account.h
#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.14.2.

2.15. 11(2012-5-23) - ,

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.15.2.

2.16. 12(2012-7-19)

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. 13(2012-7-20)

2.17.1.


#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.17.3.

  • , .

2.18. 2012-7-30

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;
}

2.19. 2012-8-2

2.19.1.

  • Map in C - . .


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:48
Processing time 0.0785 sec