C 2015-01-09 실습

Programming/C,CPP,CS 2015. 1. 9. 15:43 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include<stdio.h>

#include<stdlib.h>

 

struct bookData

{

   char name[30];

   char state[30];

   int price;

};

int main(void)

{

   struct bookData* mBookData;

   int count = 0;

   int mode;

   int i;

 

   mBookData = (struct bookData*)malloc( sizeof(struct bookData) );

 

   while(1)

   {

       printf("메뉴를선택하세요( 1. 추가, 2. 조회)\n");

       scanf("%d",&mode);

       switch(mode)

       {

       case 1:

          count++;

 

          mBookData = (struct bookData*)realloc( mBookData, sizeof(struct bookData) * count);

 

          fflush(stdin);

          gets(mBookData[count-1].name);

          fflush(stdin);

          gets(mBookData[count-1].state);

          fflush(stdin);

          scanf("%d", &mBookData[count-1].price);

          fflush(stdin);

 

 

          break;

       case 2:

          printf("%20s %10s %10s\n", "제목", "대여상태", "가격");

          for( i = 0 ; i < count ; i++)

          {

             printf("%20s %10s %10d\n", mBookData[i].name, mBookData[i].state, mBookData[i].price);

          }

          break;

       }

   }

 

    return 0;

}

 

 

 

'Programming > C,CPP,CS' 카테고리의 다른 글

Winpcap Test 01  (0) 2016.03.07
CPP 2015-01-15 수업내용 정리  (0) 2015.01.15
Run-Time Check Failure #3 - The variable 'a' is being used without being initialized.  (0) 2014.05.14
C 언어 방향키 입력활용  (0) 2014.05.03
cpp  (0) 2014.05.03