Similar documents
11장 포인터

이번장에서학습할내용 동적메모리란? malloc() 와 calloc() 연결리스트 파일을이용하면보다많은데이터를유용하고지속적으로사용및관리할수있습니다. 2

슬라이드 1

<4D F736F F F696E74202D20C1A63132B0AD20B5BFC0FB20B8DEB8F0B8AEC7D2B4E7>

untitled

<4D F736F F F696E74202D20C1A63137C0E520B5BFC0FBB8DEB8F0B8AEBFCD20BFACB0E1B8AEBDBAC6AE>

K&R2 Reference Manual 번역본

chap7.key

Microsoft PowerPoint - Chapter_09.pptx

歯7장.PDF

chap7.PDF

Microsoft PowerPoint - chap6 [호환 모드]


, ( ),, ( ), 3, int kor[5]; int eng[5]; int Microsoft Windows 4 (ANSI C2 ) int kor[5] 20 # define #define SIZE 20 int a[10]; char c[10]; float

chap8.PDF

PowerPoint 프레젠테이션

歯9장.PDF

À©µµ³×Æ®¿÷ÇÁ·Î±×·¡¹Ö4Àå_ÃÖÁ¾

Microsoft PowerPoint - chap13-입출력라이브러리.pptx

문서의 제목 나눔명조R, 40pt

Microsoft PowerPoint - Chapter14_17.pptx

Microsoft PowerPoint - Lesson14.pptx

Microsoft PowerPoint - Lesson14.pptx

Microsoft PowerPoint - chap10-함수의활용.pptx

03장.스택.key

untitled

PowerPoint Template

Microsoft PowerPoint - chap11-포인터의활용.pptx

C++-¿Ïº®Çؼ³10Àå

0. 표지에이름과학번을적으시오. (6) 1. 변수 x, y 가 integer type 이라가정하고다음빈칸에 x 와 y 의계산결과값을적으시오. (5) x = (3 + 7) * 6; x = 60 x = (12 + 6) / 2 * 3; x = 27 x = 3 * (8 / 4

Let G = (V, E) be a connected, undirected graph with a real-valued weight function w defined on E. Let A be a set of E, possibly empty, that is includ

Microsoft PowerPoint - ch10 - 이진트리, AVL 트리, 트리 응용 pm0600

untitled

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

Chapter #01 Subject

Poison null byte Excuse the ads! We need some help to keep our site up. List 1 Conditions 2 Exploit plan 2.1 chunksize(p)!= prev_size (next_chunk(p) 3

<322EBCF8C8AF28BFACBDC0B9AEC1A6292E687770>

chap10.PDF

A Hierarchical Approach to Interactive Motion Editing for Human-like Figures

chap 5: Trees

6.1 Addresses and Pointers Recall memory concepts from Ch2 ch6_testbasicpointer.c int x1=1, x2=7; double distance; int *p; int q=8; p = &q; name addre

Infinity(∞) Strategy

Chapter 4. LISTS

Chapter 4. LISTS

PowerPoint 프레젠테이션

PA for SWE2007

Chapter 4. LISTS

본 강의에 들어가기 전

chap01_time_complexity.key

untitled

슬라이드 1

PowerPoint 프레젠테이션

Microsoft PowerPoint - ch09 - 연결형리스트, Stack, Queue와 응용 pm0100

PowerPoint 프레젠테이션

<443A5C4C C4B48555C B3E25C32C7D0B1E25CBCB3B0E8C7C1B7CEC1A7C6AE425CBED0C3E0C7C1B7CEB1D7B7A55C D616E2E637070>

A Dynamic Grid Services Deployment Mechanism for On-Demand Resource Provisioning

Microsoft PowerPoint - chap06-8 [호환 모드]

Microsoft PowerPoint - 06-Pointer and Memory.pptx

Line (A) å j a k= i k #define max(a, b) (((a) >= (b))? (a) : (b)) long MaxSubseqSum0(int A[], unsigned Left, unsigned Right) { int Center, i; long Max

untitled

Microsoft PowerPoint - chap06-8.ppt

데이타전송

Microsoft PowerPoint - 자료구조2008Chap06

1장. 유닉스 시스템 프로그래밍 개요

Microsoft PowerPoint - 09_C_Language_Pointer_Advanced

Microsoft PowerPoint - lab14.pptx

02 C h a p t e r Java

1 장 C 언어복습 표준입출력배열포인터배열과포인터함수 const와포인터구조체컴파일러사용방법 C++ 프로그래밍입문

PowerPoint 프레젠테이션

PA for SWE2007

PowerPoint 프레젠테이션

商用

제1장 Unix란 무엇인가?

슬라이드 1

PowerPoint 프레젠테이션

6주차.key

untitled

/chroot/lib/ /chroot/etc/

C 언어 이론

Lab 4. 실습문제 (Circular singly linked list)_해답.hwp

untitled

기초컴퓨터프로그래밍

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt

PowerPoint 프레젠테이션

컴파일러

제12장 파일 입출력

untitled

PA0 for SSE2033

제1장 Unix란 무엇인가?

Computer Programming (2008 Fall)

5.스택(강의자료).key

ABC 10장

3. 1 포인터란 3. 2 포인터변수의선언과사용 3. 3 다차원포인터변수의선언과사용 3. 4 주소의가감산 3. 5 함수포인터

<C3CA3520B0FAC7D0B1B3BBE7BFEB202E687770>

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

Lab 3. 실습문제 (Single linked list)_해답.hwp

13 주차문자열의표현과입출력

Index

PowerPoint 프레젠테이션

Transcription:

61 62 63 64

234 235 p r i n t f ( % 5 d :, i+1); g e t s ( s t u d e n t _ n a m e [ i ] ) ; if (student_name[i][0] == \ 0 ) i = MAX; p r i n t f (\ n :\ n ); 6 1 for (i = 0; student_name[i][0]!= \ 0&& i < MAX; i++) (Static Memory Allocation) (Dynamic Memory Allocation) C,,, return 0; p r i n t f (\ n :% 5 d :, i+1); p r i n t f (% s, student_name[i]); 6 2, C [ 6-1] # i n c l u d e < s t d i o h > #define MAX 100 char student_name[max][10]; int i; for (i = 0; i < MAX; i++) [ 6-1]10 100 98 (980 ), 100, 100, MAX, 1000 MAX1000 [ 6-2]

236 237 # i n c l u d e < s t d i o h > # i n c l u d e < s t r i n g h > char text[1024][1024]; 6 3 3,,, stdlibh malloch strcpy(text[0], ); p r i n t f (% s \ n, text[0]); return 0; [ 6-1],, malloc( ), calloc( ), realloc( ) [ 6-2]1K 1K 1M 1M, [ 6-1] MAX100000 [ 6-2],, Q uiz malloc( ), (size), NULL(stdlibh ) char 1 malloc( ) char ANSI C void void (generic), malloc( ) C,

238 239 void cast malloc( ) 100 malloc( ), int student_size, index; char *student_name; p r i n t f (\ n ); s c a n f (% d, &student_size); p r i n t f (\ n ); f f l u s h ( s t d i n ) ; student_name = (char*) malloc(10*student_size); if(student_name == NULL) p r i n t f (\ n \ n ); e x i t ( 0 ) ; char *string; str = (char*)malloc(100); if((str=(char*) mallor(100))==null) if(str = = NULL) p r i n t f (Not Enough memoryn ); e x i t ( 1 ) ; 50 50 # i n c l u d e < s t d i o h > # i n c l u d e < s t d l i b h > for (index = 0; index < student_size; index++) p r i n t f ( % d:, index+1); gets(student_name + (index*10)); p r i n t f (\ n \ n \ ); for (index = 0; index < student_size; index++) p r i n t f (\ n % d, index+1); p r i n t f (% s, student_name + (index*10)); f r e e ( s t u d e n t _ n a m e ) ; return 0;

240 241 malloc( ) fflush( ) fflush(stdin), student_name 10byte student_size Q uiz char *student_name; student_name = (char*) malloc(10*student_size); calloc( ) 0, #include <sdtlibh> #include <stdioh> #include <stringh> void *calloc(size_t number_items, size_t block_size); #include <stdlibh> int size, index, *ptr; p r i n t f (\ n ); s c a n f (% d, &size); ptr = (int *) calloc(size, sizeof(int)); if(ptr == NULL) p r i n t f (\ n ); p r i n t f ( \ n ); for (index = 0; index < size; index++) p r i n t f ( ); s c a n f (% d,ptr + (index*sizeof(int))); p r i n t f (\ n \ ); for (index = 0; index < size; index++) f r e e ( p t r ) ; p r i n t f (% d \ t,*(ptr + (index*sizeof(int)))); [ 6-4]calloc( ) size int

242 243 calloc( ) pre-ansi char, ANSI C void int s c a n f (% d,& s i z e ); ptr = (int *) calloc (size, sizeof(int)); realloc( ) malloc( ) calloc( ) f r e e ( m e s s a g e ) ;, realloc( ) realloc( )size originalblock originalblock, size [ 6-5]realloc( ) #include <stdioh> #include <stdlibh> #include <stringh> char buf[80], *message; p r i n t f (\ n ); g e t s ( b u f ) ; message = (char *)realloc(null, strlen(buf) + 1); strcpy(message, buf); p r i n t f (\ n % s \ t % p \ n, message, message); p r i n t f (\ n ); g e t s ( b u f ) ; message = (char *)realloc(null, strlen(buf) + 1); strcpy(message, buf); p r i n t f ( % s \ t % p \ n, message, message); free( ) free( ), free( ), [ 6-3], [ 6-4], [ 6-5] free( ) free( ) [ 6-6] # i n c l u d e < s t d i o h > # i n c l u d e < s t d l i b h >

244 245 int *ptr; ptr = (int *) malloc(sizeof(int)); *ptr = 1234; p r i n t f (*ptr : %d\n, *ptr); f r e e ( p t r ) ; p r i n t f (*ptr : %d\n, *ptr); [ 6-6] free( ),, memset( ) c (unsigned char ) block size memset( ), 0 block, [ 6-7] memset( ) #include <stdioh> #include <stdlibh> #include <stringh> struct student_node ; int number; char name[20]; struct student_node *student; student = (struct student_node *) malloc(sizeof (struct s t u d e n t _ n o d e ) ) ; p r i n t f ( : %d, % s \ n, student -> number, student -> n a m e ); memset(student, 0, sizeof(struct student_node)); p r i n t f ( : %d, % s \ n, student -> number, student -> n a m e ); f r e e ( s t u d e n t ) ; [ 6-7] malloc( ), memset( ) student = (struct student_node *) malloc(sizeof (struct s t u d e n t _ n o d e ) ) ; p r i n t f ( : %d, % s \ n, student -> number, student -> n a m e ); - 842150451, malloc( ) memset( ) student (0)

246 247 memset(student, 0, sizeof(struct student_node)); p r i n t f ( % d, % s \ n, student ->number, student -> n a m e ); memcpy( ) from to size, c c, from size c [ 6-8]memcpy( ) memmove( ) memmove( ) 2 from size to size, memmove( ) from, to [ 6-9]memmove( ) #include <stdioh> #include <stringh> char string1[20]=s t r i n g 1 ; char string2[20]=new string ; char *ptr; ptr = (char *)memcpy(string1, string2, 20); if (ptr) e l s e p r i n t f ( % s \ n, string1); p r i n t f ( \ n ); 6 4 #include <stdioh> #include <stringh> char string[20]=0 123456789 a b c d e f g h i ; memmove(string+5, string, 10); p r i n t f (memmove % s \ n, s t r i n g ); [ 6-9]string 10 "0123456789"string memcpy( ) memmove( ) memcpy( ), to from (Linked List) (Tree) (Node) [ 6-1]

248 249, [ 6-1 ], h e a d rear( tail) NULL [ 6-10] #include <stdioh> #include <stringh> #include <stdlibh> char str1[50] = memset( ), memcpy( ), memmove( ) ; char str2[50] = 1 234567890 ; char str3[50] = a b c d e f g h i j k l m n ; p r i n t f (string1 = %s\n, str1); memset(str1+3, *, 8); p r i n t f (memset( ) = %s\n, str1); p r i n t f (string2 = %s\n, str2); memcpy(str2+2, str2+5, 3); p r i n t f (memcpy( ) = %s\n, str2); [ 6-10]memset( ), memcpy( ), memmove( ) memset( ) memset( ) memset( ) str+3 str14 str14 11 * char str1[50] = memset( ), memcpy( ), memmove( ) ; p r i n t f (string1 = %s\n, str1); memset(str1+3, *, 8); p r i n t f (memset( ) = %s\n, str1); memcpy( ), str2+5( 6) 3( 678) str2+2( 2), char str2[50] = 1 234567890 ; p r i n t f (string2 = %s\n, str2); memcpy(str2+2, str2+5, 3); p r i n t f (memcpy( ) = %s\n, str2); memmove( ) memcpy( ),, p r i n t f (string3 = %s\n, str3); memcpy(str3+2, str3+5, 3); p r i n t f (memmove( ) = %s\n, str3); char str3[50] = a b c d e f g h i j k l m n ; p r i n t f (string3 = %s\n, str3); memcpy(str3+2, str3+5, 3); p r i n t f (memmove( ) = %s\n, str3);

250 251 # i n c l u d e < s t d i o h > # i n c l u d e < s t d l i b h > # i n c l u d e < s t r i n g h > struct student_node ; int number; char name[20]; struct student_node *next; char number, name[20]; struct student_node *head, *rear, *ptr; head = ptr = NULL; for (number = 1; ;number++) p r i n t f ( %d:, number); g e t s ( n a m e ) ; if (name[0] == \ 0 ) break; ptr = (struct student_node *) malloc(sizeof(struct s t u d e n t _ n o d e ) ) ; if (ptr == NULL) p r i n t f ( \ n ); e x i t ( 0 ) ; ptr -> number = number; strcpy(ptr -> name, name); ptr -> next = NULL; if (head == NULL) e l s e head = rear = ptr; rear -> next = ptr; rear = ptr; /* */ p r i n t f (\ n \ ); ptr = head; while (ptr!= NULL) p r i n t f (%d\t: %s\n, ptr -> number, ptr -> n a m e ); ptr = ptr -> n e x t ; /* while (head!= NULL) return 0; ptr = head -> n e x t ; f r e e ( h e a d ) ; head = ptr; [ 6-11], ptr= (struct student *) malloc(sizeof(struct student)); rearnext, rear if(head == NULL) head = rear = ptr;

252 253 e l s e rear -> next = ptr; rear = ptr;, [ 6-2] head rear ptr = head; while (ptr!= NULL) p r i n t f (%d\t: %s\n, ptr -> number, ptr -> n a m e ); ptr = ptr -> n e x t ;, head rear while (head!= NULL) ptr = head ->n e x t ; f r e e ( h e a d ) ; head = ptr; free( ), head int i; char *ptrnull, *cur, ch; c u rp t r(char*) malloc(27); for (i0, ch Z ; i < 26; i, ch ) * c u r + +ch; * c u r \ 0 ; p r i n t f (% s, ptr); free(ptr);, ( 100, Ctrl+Z ) while (head!= NULL) f r e e ( h e a d ); head = head -> n e x t ;

254,? strcat(const char* s1, const char* s2) s1s2 s1 s3s1s2, s3