옵션 |
|
int PrintScreen();
int PutFood(int Top,char *Dosirak[], char *input);
int EatFood(int Top,char *Dosirak[], int count);
void SearchFood(char *Dosirak[]);
void main()
{
int Top = 4;
int count = 0;
char input[10];
char *Five_Dan_Dosirak[5] = {"족발","꽃등심","삼겹살","갈비","불고기"};
while (1)
{
switch (PrintScreen())
{
case 1:
system("cls");
printf("도시락에 넣을 음식을 입력하세요. : ");
scanf("%s", input);
Top = PutFood(Top,Five_Dan_Dosirak,input);
SearchFood(Five_Dan_Dosirak);
break;
case 2:
system("cls");
Top = EatFood(Top,Five_Dan_Dosirak, count);
SearchFood(Five_Dan_Dosirak);
break;
case 3:
exit(0);
}
}
}
int PrintScreen()
{
int input;
printf("\n\n\n\t\t\t\t\t\t 도시락 \n");
printf("\t\t\t\t\t\t ====== \n\n");
printf("\t\t\t\t\t 1. 넣기\n");
printf("\t\t\t\t\t 2. 먹기 \n");
printf("\t\t\t\t\t 3. 종료\n\n");
printf("\t\t\t\t 번호를 입력하세요 : ");
scanf("%d", &input);
return input;
}
int PutFood(int Top,char *Dosirak[], char *input)
{
if (Top == 5) {
printf("FULL\n");
return 1;
}
else
{
Dosirak[++Top] = input;
return Top;
}
}
int EatFood(int Top,char *Dosirak[],int count)
{
int ETop = Top;
int Ecount = count;
if (ETop == -1) {
printf("No Data");
return ETop;
}
else
{
printf(" %s Eat\n", Dosirak[ETop]);
Dosirak[ETop] = "\0";
return --ETop;
}
printf("\n%d\n",Ecount);
}
void SearchFood(char *Dosirak[])
{
int i;
for (i = 4; i >= 0; i--) printf("%d 단 : %s ", i + 1, Dosirak[i]);
}
스택으로 구현했는데 Push할때마다 값이 이상합니다.