Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- greedy
- dfs
- String
- 생활코딩
- Algorithm
- 정수론
- 따라하면서 배우는 C언어
- programmers
- C
- 백준
- BFS
- C언어
- Python
- DP
- Cleancode
- php
- udemy
- sorting
- Math
- 인프런
- web
- 따배씨
- JavaScript
- graph
- BOJ
- 따라하며 배우는 C언어
- Algospot
- 종만북
- server
- BASIC
Archives
- Today
- Total
몽상실현개발주의
[따배씨] 14.13 구조체의 배열을 사용하는 함수 본문
따배씨 - 따라하며 배우는 C언어
14강 구조체_2
14.13 구조체의 배열을 사용하는 함수
#include <stdio.h>
#define SLEN 101
struct book
{
char name[SLEN];
char author[SLEN];
};
void print_books(const struct book books[], int n);
int main()
{
struct book my_books[3]; // = {"The Great Gatsby", "F. Scott Fitzgerald"},...};
my_books[0] = (struct book){"The Great Gatsby", "F. Scott Fitzgerald"};
my_books[1] = (struct book){"Hamlet", "William Shakespeare"};
my_books[2] = (struct book){"The Odyssey", "Homer"};
print_books(my_books, 3);
return 0;
}
void print_books(const struct book books[], int n)
{
for (int i = 0; i < n; i++)
{
printf("Book %d :\"%s\" written by \"%s\"\n", i + 1, books[i].name, books[i].author);
}
}
- 구조체 배열 사용
#include <stdio.h>
#include <stdlib.h>
#define SLEN 101
struct book
{
char name[SLEN];
char author[SLEN];
};
void print_books(const struct book books[], int n);
int main()
{
struct book* my_books = (struct book*)malloc(sizeof(struct book) * 3);
if (!my_books) exit(1);
my_books[0] = (struct book){"The Great Gatsby", "F. Scott Fitzgerald"};
my_books[1] = (struct book){"Hamlet", "William Shakespeare"};
my_books[2] = (struct book){"The Odyssey", "Homer"};
print_books(my_books, 3);
return 0;
}
void print_books(const struct book* books, int n)
{
for (int i = 0; i < n; i++)
{
printf("Book %d :\"%s\" written by \"%s\"\n", i + 1, books[i].name, books[i].author);
}
}
- 구조체 배열을 pointer 로 구현
이 글의 모든 사진과 내용의 출처는 홍정모 교수님께 있음을 알려드립니다.
http://blog.naver.com/atelierjpro
실리콘 밸리의 프로그래머 : 네이버 블로그
안녕하세요! 홍정모 블로그에 오신 것을 환영합니다. 주로 프로그래밍 관련 메모 용도로 사용합니다. 강의 수강하시는 분들은 홍정모 연구소 카페로 오세요.
blog.naver.com
http://www.inflearn.com/course/following-c
홍정모의 따라하며 배우는 C언어 - 인프런 | 강의
'따배씨++'의 성원에 힘입어 새롭게 개발된 C 언어로 시작하는 프로그래밍 입문 강의입니다. '따배씨'와 함께 프로그래밍 인생을 업그레이드 해보세요., 따라하며 배우는 C언어 '따배씨++'의 성원
www.inflearn.com
'Language > C' 카테고리의 다른 글
[따배씨] 14.15 공용체 Union 의 원리 (0) | 2021.07.05 |
---|---|
[따배씨] 14.14 구조체 파일 입출력 연습문제 (0) | 2021.07.04 |
[따배씨] 14.12 익명 구조체 (0) | 2021.06.28 |
[따배씨] 14.11 신축성 있는 배열 멤버 (0) | 2021.06.28 |
[따배씨] 14.10 복합 리터럴 (0) | 2021.06.26 |
Comments