C++프로그래밍

2013.04.16_C언어_구조체

성엽이 2013. 4. 16. 16:43

▶ 구조체 합체!


 

typedef struct tage
{

}Newtype;

 struct tage
{

};

typedef struct tage Newtype;














: 위에 두개는 똑같다!



 
#include < stdio.h >

typedef struct
{
  char name[20];
  char pub[10];
  unsigned int price;
  char author[10];
  char date[11];
}BOOK;

int main()
{
  int i;

  BOOK item[3];  // 세권의 내용을 한번에 입력받고, 종료하기전에 
      // 세권의 내용을 한번에 출력해주는 프로그램!
  for(i=0 ;i < 3;++i)
  {
    printf("책이름 & 출판사 & 가격 & 저자 & 출판년도 : ");
    scanf("%s %s %d %s %s", item[i].name, item[i].pub, &item[i].price, item[i].author, item[i].date);      
  }

  for(i=0; i < 3; ++i)
  {
    printf("%s %s %d %s %s\n", item[i].name, item[i].pub, item[i].price, item[i].author, item[i].date);
  }
  
  return 0;
}


: 도서리스트 3개 입력받고 3개 출력되는 프로그램

-----------

9_3.c


9_4.c


booklist.c


test.c

---------