struct3 C언어로 Array of struct 만들기 Array of struct 이다. #include #include #include #define Max_Col 512 #define Max_Row 300 // Up to 3000000, it's ok for some computers. typedef struct Item { char name[Max_Col]; int quantity; } Item; void exit_if_null(void *ptr, char *msg) { if (!ptr) { printf("unexpected null pointer: %s\n", msg); exit(EXIT_FAILURE); } } Item* create_array(int size) { Item *p = malloc(size * sizeof(Item)); exit_if.. 2023. 7. 4. C언어 구조체의 동적배열 사용하기 (2) C언어 구조체의 동적배열 사용하기를 소개한다. 1탄 보다 좀 더 발전되고, 간결하며 정돈된 느낌이 든다. #include #include #include typedef struct Data { int num; char *name; } Data; typedef struct Array { Data **base; size_t size; size_t count; } Array; void exit_if_null(void *ptr, char *msg) { if (!ptr) { printf("unexpected null pointer: %s\n", msg); exit(EXIT_FAILURE); } } Data *NewData(int num, const char *name) { Data *data = (Data *)m.. 2021. 2. 16. C언어 구조체의 동적배열 사용하기 C언어 구조체의 동적배열 사용하기를 소개한다. #include #include #include typedef struct { int Amount; char * name; } Store; typedef struct { // array of structs Store *array; size_t used; size_t size; } Array; void exit_if_null(void *ptr, char *msg) { if (!ptr) { printf("unexpected null pointer: %s\n", msg); exit(EXIT_FAILURE); } } void initArray(Array *a, size_t initialSize) { // Allocate initial space a->array = .. 2021. 2. 8. 이전 1 다음