C 2015-01-09 실습
#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;
}