일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- String 클래스
- StringBuffer 클래스
- C# 소스 코드
- java
- 디딤돌 Java 언어 Part1
- 소프트웨어 접근성
- C언어
- 파일 입출력
- 동적 메모리 할당
- C언어 소스
- 소스 구현
- 설계 패턴
- 무료 Java
- C언어 표준 라이브러리 함수 사용법 가이드
- C#
- 알고리즘
- C언어 소스 코드
- Escort GoF의 디자인 패턴
- math.h
- 소스 코드
- C++
- C언어 표준 라이브러리 함수 가이드
- JAVA 언어
- 디딤돌 C++
- XML.NET
- 클래스 다이어그램
- 디딤돌 C언어
- gof의 디자인 패턴
- 소스 파일
- 소프트웨어 설계
- Today
- 11
- Total
- 125,084
목록동적 메모리 할당 (10)
프로그램 소스
[C언어 소스] 학생 구조체 동적 메모리 할당 //Student.h#pragma once typedef struct _Student Student;#define MAX_NAME_LEN 20struct _Student//학생{ char name[MAX_NAME_LEN];// 학생 이름 int num;// 학생 번호}; Student *New_Student(const char *name,int num);//학생은 생성할 때 이름, 번호를 부여한다.void Delete_Student(Student *stu);//동적으로 생성한 학생 개체를 소멸void Student_Study(Student *stu);//학생이 공부하다.void Student_View(Student *stu);//학생 정보 보기 //Stude..
[C언어 소스] 동적 할당한 메모리의 크기를 확장(realloc 함수 사용) #include #include int *base = 0; //저장소의 위치 정보 int asize = 0; //현재 저장소의 용량 int usage = 0; //저장소에 보관한 요소 개수 void Input(int num); //저장소에 보관하기 void Resize();//저장소의 용량 변경하기 void View();//저장소의 정보 보기 int main() { Input(3); View(); Input(5); View(); Input(7); View(); Input(9); View(); return 0; } void Input(int num) { if(asize == usage) { Resize(); } base[usage..
[C언어 소스] 기본 형식 동적 메모리 할당(calloc 함수 사용 예) #include #include int main() { int *pi = (int *)calloc(1, sizeof(int)); //원하는 형식 포인터로 형변환 printf("초기: %d \n",*pi); *pi= 20; //간접 연산으로 사용 printf("간접 연산을 수행한 후: %d\n",*pi); free(pi); //더 이상 필요없을 때 해제 return 0; } 실행 결과초기: 0 간접 연산을 수행한 후: 20 본문[디딤돌 C언어] 84. calloc 함수
[C언어 소스] n명의 학생 성적 입력받아 출력(malloc 함수 사용) #include #include void InputScores(int *base,int asize); //asize 명의 성적을 입력받는 함수 void ViewScores(int *base,int asize); //asize 명의 성적을 출력하는 함수 int InputScore(int num); //num 번의 학생 성적을 입력받는 함수 int main() { int *base = 0; //동적으로 할당받아 학생들의 성적을 관리할 메모리의 시작 주소 int max_stu= 0; //관리할 학생 수 printf("최대 관리할 학생 수를 입력하세요.\n"); scanf_s("%d",&max_stu); base = (int *)mallo..
[C언어 소스] malloc 함수 사용 (기본 형식 메모리 동적 할당) #include #include int main() { int *pi = (int *)malloc(sizeof(int)); //원하는 형식 포인터로 형변환 printf("초기: %d \n",*pi); *pi= 20; //간접 연산으로 사용 printf("간접 연산을 수행한 후: %d\n",*pi); free(pi); //더 이상 필요없을 때 해제 return 0; } 실행 결과초기: -842150451 간접 연산을 수행한 후: 20 본문[디딤돌 C언어] 83. malloc 함수
학생 성적 관리 프로그램 #pragma warning(disable:4996) #include #include #include #define MAX_NAME_LEN 20 enum Subject { KOREAN, ENGLISH, MATH, MAX_SUBJECT }; const char *stitle[MAX_SUBJECT] = { "국어","영어","수학" }; typedef struct _Student Student; struct _Student { int num; char name[MAX_NAME_LEN]; int scores[MAX_SUBJECT]; }; #define DEF_FNAME "data.stu" int max_student; Student **stues; void Init(); void Ru..
학생 성적 관리 프로그램 #pragma warning(disable:4996) #include #include #define MAX_NAME_LEN 20 enum Subject { KOREAN, ENGLISH, MATH, MAX_SUBJECT }; const char *stitle[MAX_SUBJECT] = { "국어","영어","수학" }; typedef struct _Student Student; struct _Student { int num; char name[MAX_NAME_LEN]; int scores[MAX_SUBJECT]; }; #define DEF_FNAME "data.stu" #define MAX_STUDENT 50 Student *stues[MAX_STUDENT]; void Init()..
학생 성적 관리 프로그램(동적 메모리 할당,파일 입출력) #pragma warning(disable:4996) #include #include #define MAX_NAME_LEN 20 enum Subject { KOREAN, ENGLISH, MATH, MAX_SUBJECT }; const char *stitle[MAX_SUBJECT] = { "국어","영어","수학" }; typedef struct _Student Student; struct _Student { int num; char name[MAX_NAME_LEN]; int scores[MAX_SUBJECT]; }; #define DEF_FNAME "data.stu" int max_student; Student *stues; void Init();..
[C언어 소스] 성적 관리 프로그램 - 학생 데이터 동적 메모리 할당 //성적 관리 프로그램 - 배열을 동적 메모리 할당//학생 번호 순으로 동적 배열에 보관//학생 데이터도 동적으로 할당//최대 학생 수를 프로그림 시작 시에 사용자가 결정//입력 오류에 관한 예외 처리 없음 #include #include #include #include #define MAX_NLEN 20 //최대 이름 길이#define MAX_SUBJECT 3 //과목 수typedef struct {//학생 구조체 정의 char name[MAX_NLEN + 1];//이름 int num; //번호 int scores[MAX_SUBJECT];//국,영,수 성적}Student; const char *stitles[MAX_SUBJECT] =..
[C언어 소스] 성적 관리 프로그램 - 동적 메모리 할당 //성적 관리 프로그램 - 배열을 동적 메모리 할당//학생 번호 순으로 동적 배열에 보관//학생 데이터는 동적으로 할당받지 않음//최대 학생 수를 프로그림 시작 시에 사용자가 결정//입력 오류에 관한 예외 처리 없음 #include #include #include #include #define MAX_NLEN 20 //최대 이름 길이#define MAX_SUBJECT 3 //과목 수typedef struct {//학생 구조체 정의 char name[MAX_NLEN + 1];//이름 int num; //번호 int scores[MAX_SUBJECT];//국,영,수 성적}Student; const char *stitles[MAX_SUBJECT] = {..