본문 바로가기

SW Study/윤성우 C 프로그래밍

도전! 프로그래밍4 도전1

#include <stdio.h>

typedef struct booklist
{
   char author[20];
   char title[50];
   int page;
} BOOKLIST;

void BookInfo(BOOKLIST *pbook)
{
   printf("author: "); scanf("%s", pbook->author);
   printf("title: "); scanf("%s", pbook->title);
   printf("page: "); scanf("%d", &pbook->page);
}

void ShowBookInfo(BOOKLIST pbook)
{
   printf("author: %s \n", pbook.author);
   printf("title: %s \n", pbook.title);
   printf("page: %d \n", pbook.page);
}

int main(void)
{
   BOOKLIST book[3];
   int i;

   printf("====Book Info Input==== \n");
   for (i = 0; i < 3; i++)
      BookInfo(&book[i]);
   
   printf("\n");

   printf("====Book Info Output==== \n");
   for (i = 0; i < 3; i++)
   {
      printf("book%d \n", i + 1);
      ShowBookInfo(book[i]);
   }

   return 0;
}