반응형


#include <stdio.h>

#include <stdlib.h>
#include <string.h>

//Cars 구조체 

typedef struct Cars
{
      int CarNumber;
      char Color[50];
}Car;


 //각 기능을 함수처리

int Putin();
void insert(Car **pList);
void display();
void print(Car **pList);
void Putout(Car **pList);
void Pnt(Car **pList);

 

int Low, Number;
char Color[10];


void main()
{
      int N;
 
      Car *str[6]={NULL,};;
      do
     {
            display();
            N=Putin();
  
            switch(N)
           {
               case 1: system("cls"); insert(str);
                    break;
               case 2: system("cls"); Putout(str);
                    break;
               case 3: system("cls"); print(str);
                    break;
               case 4: system("cls"); Pnt(str);
                    break;
               default:
                    break;
             }
        }while(N != 0);
 system("cls");//화면 깨긋하게 지워진다
 
}

void insert(Car **pList)
{
         printf("열을 입력하세요:");
         scanf("%d", &Low);
 
         pList[Low]=(Car *)malloc(sizeof(Car));
         printf("차량 번호를 입력하세요:");
         scanf("%d",&Number);
         printf("색상을 입력하세요:");
         scanf("%s",Color);
         pList[Low]->CarNumber=Number;
         strcpy(pList[Low]->Color, Color);
}

void Putout(Car **pList)
{
         printf("열을 입력하세요:");
         scanf("%d", &Low);
         free(pList[Low]);
         pList[Low]=NULL;
         system("cls");
 }

void print(Car **pList)
{
          int i;
          for(i=1;i<6;i++)
         {
                if(pList[i]==0)
                {
                       printf("[%d]차량이 존재 하지 않습니다.\n",i);
                 }else
                {
                       printf("[%d] 칸 \n",i);
                       printf("CarNumber : %d  ", (*pList[i]).CarNumber);
                       printf("CarColor : %s", (*pList[i]).Color);
                       puts("");
                 }
  
           }
}

void Pnt(Car **pList)
{
          int i;
          for(i=1;i<6; i++)
         {
               if(pList[i]==0)
              {
                      printf("[X]");
               }else
              {
                      printf("[O]");
               }
  
          }
          puts("");
}

void display()
{
          printf("----------------------------\n");
          printf("| 1. 차량 번호, 색상 등록  |\n");
          printf("| 2. 차량 번호, 색상 빼기  |\n");
          printf("| 3. 차량 번호, 색상 확인  |\n");
          printf("| 4. 주차 공간 확인        |\n");
          printf("----------------------------\n");
}


int Putin()
{
        int N;
        printf("메뉴를 입력하세요:");
        scanf("%d", &N);
        return N;
}

 

반응형

'프로그래밍 > Language C' 카테고리의 다른 글

[C언어] 계산기 프로젝트(공학용 계산기 C로 구현 최대한)  (31) 2011.11.15
[C언어] 영화관 연습 by Hwang  (4) 2011.11.15
[C언어] 이진모드  (0) 2011.11.15
[C언어] IO  (0) 2011.11.15
[C언어] 구조체 리뷰  (0) 2011.11.15