본문 바로가기
728x90
반응형
SMALL

개념175

chapter 17) 구조체 배열을 초기화하고 출력 #include struct address { char name[20]; int age; char tel[20]; char addr[80]; }; int main(void){ struct address list[5] = { {"test1", 23, "111-1111", "core1"}, {"test2", 35, "222-2222", "core2"}, {"test3", 19, "333-3333", "core3"}, {"test4", 15, "444-4444", "core4"}, {"test5", 45, "555-5555", "core5"} }; for( int i= 0; i< 5; i++){ printf("%10s%5d%15s%20s\n", list[i].name, list[i].age, list[i].t.. 2024. 10. 4.
chapter 17) 자기 참조 구조체로 list 만들기 #include struct list{ int num; struct list *next; }; int main(void){ struct list a = {10, 0}, b = {20,0}, c = {30,0}; struct list *head = &a, *current; a.next = &b, b.next = &c; printf("head -> num : %d\n", head -> num); printf("head -> next -> num : %d\n", head -> next -> num); printf("list all :"); current = head; while(current != NULL){ printf("%d ", current -> num); current = current -> next.. 2024. 10. 3.
chapter 17) 열거형을 사용한 프로그램 #include enum season {SPRING, SUMMER, FALL, WINTER}; int main(void){ enum season ss; char *pc = NULL; ss = SPRING; switch (ss){ case SPRING: pc = "inline"; break; case SUMMER: pc = "swimming"; break; case FALL: pc = "trip"; break; case WINTER: pc = "skiing"; break; } printf("my regier activity => %s\n", pc); return 0; } ### Enum 선언 - `enum season {SPRING, SUMMER, FALL, WINTER};`는 `season`이라는 열거형.. 2024. 10. 2.
chapter 17) 배열과 포인터를 멤버로 갖는 구조체 사용 #include #include #include struct profile{ char name[20]; int age; double height; char *intro; }; int main(void){ struct profile yuni; strcpy(yuni.name, "hayun"); yuni.age = 17; yuni.height = 164.7; yuni.intro = (char * )malloc(80); printf("introduce : "); gets(yuni.intro); printf("name ; %s\n", yuni.name); printf("age : %d\n", yuni.age); printf("height : %.1lf\n", yuni.height); printf("intro : .. 2024. 10. 1.
728x90
반응형
LIST