본문 바로가기

C\C++

(32)
도서관리 프로젝트 개요 파일 읽기/쓰기를 이용하여 DLL 자료구조를 이용하여 도서관리를 위한 자료를 편집할 수 있는 프로그램을 작성. 목표 book_original.txt 100 1 고래 홍길동 1923 200 2 사자 이순신 1919 300 3 만세 유관순 1929 400 4 운동 김순자 2010 Code bookManagement.c #include"bookDLL.h" int main(void) { BOOK_t* headNode = initailize_DLL(); BM_main(headNode); free(headNode); return 0; } bookDLL.h #pragma once #include #include #include #include #define U_SIZEOF (unsigned)sizeof #def..
Linked List 회원관리 프로그램 개요 Linked list 자료 구조를 이용하여 회원관리를 위한 프로그램 작성 Code - Main 함수 - #include #include #include #include #include"DLL.h" int main(void) { NODE_t* ptrHeadNode = initailize_DLL(); menuSelect(ptrHeadNode); free(ptrHeadNode); return 0; } - 사용자 정의 함수 "DLL.h" - //#pragma once #define U_SIZEOF (unsigned)sizeof #define _LINE linePrint() #define STRMAX 20 typedef struct MEM { char name[STRMAX]; int age; char pho..
malloc, realloc 예제 개요 malloc과 realloc을 사용하여 메모리를 동적 선언하는 코드작성. Code #include #include #define U_SIZEOF (unsigned)sizeof int iSum(int* ptr, int size); void in_num(int* ptr); void ptrError(int* ptr); int main(void) { int* iPtr = NULL; in_num(iPtr); free(iPtr); return 0; } void in_num(int* ptr) { int iNum, iAddNum; do { printf("몇개의 숫자를 입력하겠습니까? (0:종료) : "); scanf_s("%d", &iNum); if (iNum < 0) { printf("값이 0보다 작습니다.\n..
포인터 문제 개요 2개의 정수의 합과 차를 동시에 반환하는 함수를 작성하고 테스트하라. 포인터 매개 변수를 사용한다. x=100 y=200 void get_sum_diff(int x, int y, int *p_sum, int *p_diff) { } 목표 원소들의 합= 300 원소들의 차= -100 Code #include void get_sum_diff(int x, int y, int* p_sum, int* p_diff); int main(void) { int x = 100, y = 200, sum, diff; get_sum_diff(x, y, &sum, &diff); printf("원소들의 합 : %d\n",sum); printf("원소들의 차 : %d\n",diff); return 0; } void get_sum..
배열 문제 개요 배열 days[] 를 아래와 같이 초기화하고 배열 원소의 값을 다음과 같이 출력하는 프로그램 을 작성하라. 목표 1월은 31일까지 있습니다. 2월은 29일까지 있습니다. ..... Code #include int main(void) { int days[] = { 30,29,31,30,31,30,31,31,30,31,30,31 }; for (int i = 1; i aRand[j]) { temp = aRand[i]; aRand[i] = aRand[j]; aRand[j] = temp; } } } for (int i = 0; i < 10; i++) { printf("%5d", aRand[i]); } printf("\nMIN : %d\tMAX : %d",aRand[0],aRand[9]); } Output 개..
구조체 문제 개요 구조체를 이용하여 복소수를 다음과 같이 정의하고 복소수의 덧셈을 수행하는 함수를 작성하고 테스트하시오.​ Code #include typedef struct complex{ double real; double imag; }Com_s; Com_s com_add(Com_s c1, Com_s c2); int main(void) { Com_s c1, c2, res; printf("Input 1st complex No. : "); scanf_s("%lf %lf",&c1.real,&c1.imag); printf("Input 2nd complex No. : "); scanf_s("%lf %lf", &c2.real, &c2.imag); res = com_add(c1,c2); printf("Result : %0.2..
최대 최소 구하기(bubble sort) 개요 5개의 숫자를 입력 받고 최대값과 최소값을 구하라. Code #include #define MAX 5 void input(int arr[]); void maxmin(int arr[]); void output(int arr[]); int main(void) { int arrInt[MAX]; input(arrInt); maxmin(arrInt); output(arrInt); return 0; } void input(int arr[]) { for (int i = 0; i < MAX; i++) { printf("%d번째 숫자 :",i+1); scanf_s("%d", &arr[i]); } } void maxmin(int arr[]) { int i, j, temp; for (i = 0; i < MAX ; i+..
String 관련 예제 개요 1. 문자열 안에 포함된 특정한 문자의 개수를 세는 함수 int str_chr(char *s, int c)를작성하라. s는 문자열이고 c는 개수를 셀 문자이다. 목표 실행결과 문자열을 입력하시오: I am a boy 개수를 셀 문자를 입력하시오: a a의 개수: 2 Code #include #include #define INSIZE (unsigned)sizeof int str_chr(char* s, int c); int str_chr(char* s, int c) { int cnt = 0; for (int i = 0; i