10월 7, 2018의 게시물 표시

C 언어 자기 참조 구조체

#include <stdio.h> #include <stdlib.h> struct linked_list {         char name[20];         int age;         struct linked_list *left_link;         struct linked_list *right_link; }; int main() {         struct linked_list first_person =  {"남동길", 28, NULL, NULL};         struct linked_list second_person = {"아무개", 30, NULL, NULL};         struct linked_list third_person = {"박서방", 35, NULL, NULL};         first_person.right_link = &second_person;         second_person.left_link = &first_person;         second_person.right_link = &third_person;         third_person.left_link = &second_person;         printf("첫번째 사람 : %s\t%d\n",first_person.name, first_person.age);         prin...

C 언어 구조체 배열의 동적 할당

포인터변수를 선언하고 malloc()함수를 사용해서 메모리를 할당하고 free()함수로 해제 #include <stdio.h> #include <stdlib.h> struct s_teacher {         char name[20];         int age;         long number; }; struct s_student {         char name[20];         int age;         long number;         struct s_teacher* pTeacher; //포인터 변수 }; void inputCounts(int *sCnt, int *tCnt); int main() {         int sCnt =0, tCnt =0;         inputCounts(&sCnt, &tCnt);         if(sCnt <= 0 || tCnt <= 0)         {                 printf("선생과 학생수는 1명 이상이여야 됩니다.\n");                 return 0;         }         printf("선생 수 : %d, \t 학생 수  : %d\n", ...