728x90 반응형 SMALL 개념/혼자 공부하는 C언어148 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. chapter 17) 명령형 인수를 출력하는 프로그램 #include int main(int argc, char **argv){ int i; for (i = 0; i< argc; i++){ printf("%s\n", argv[i]); } return 0; } ### 주요 구성 요소 - `int main(int argc, char **argv)`는 메인 함수의 헤더로, 프로그램이 시작될 때 호출됩니다. 여기서 `argc`는 커맨드 라인에서 전달된 인자의 총 개수를 나타내고, `argv`는 그 인자들의 문자열을 가리키는 포인터의 배열입니다. `argv[0]`은 프로그램의 이름을 나타내는 문자열이며, `argv[1]`부터 실제로 전달된 인자들을 나타냅니다. - `for` 루프는 `i = 0`에서 시작하여 `argc`보다 작을 때까지 반복되며, `i`를 1씩 증가.. 2024. 9. 30. chapter 17) 다른 구조체를 멤버로 갖는 구조체 사용 #include struct profile{ int age; double height; }; struct student{ struct profile pf; int id; double grade; }; int main(void){ struct student yuni; yuni.pf.age = 17; yuni.pf.height = 164.5; yuni.id = 315; yuni.grade = 4.3; printf("age : %d\n", yuni.pf.age); printf("height : %d\n", yuni.pf.height); printf("class ; %d\n", yuni.id); printf("grade : %.1lf\n", yuni.grade); return 0; } ### 코드 설명 - `s.. 2024. 9. 29. 이전 1 ··· 3 4 5 6 7 8 9 ··· 37 다음 728x90 반응형 LIST