94. 사용하는 예제 코드

◈ Program.c

#include <stdio.h>
#include "Member.h"
#include "EHArray.h"
 
Member *MakeMember(int nth);
void ExampleSeq();
void ExampleIndex();
 
int main()
{
    ExampleSeq();
    ExampleIndex();
    return 0;
}
Member *MakeMember(int n)
{
    char name[MAX_NAME_LEN+1]="";  
    printf("%d 번 회원 이름 입력:",n);
    scanf_s("%s",name);  
    return NewMember(n,name);
}
void InputSeq(EHArray *arr);
void ViewSeq(EHArray *arr);
void EndSeq(EHArray *arr);
void ExampleSeq()
{
    EHArray *arr = 0;
    arr = NewEHArray(0,0);
    InputSeq(arr);    
    ViewSeq(arr);
    EndSeq(arr);
}
void InputSeq(EHArray *arr)
{
    int num = 0;
    Member *member = 0;
    printf("생성할 회원 번호:");
    scanf_s("%d",&num);
    member = MakeMember(num);
    EHArrayPushBack(arr,member);
}

void ViewSeq(EHArray *arr)
{
    Iterator seek;
    Iterator end;
    Member *member = 0;
    seek = EHArrayBegin(arr);
    end = EHArrayEnd(arr);
    for(   ; seek != end; ++seek)
    {
        member = (Member *)(*seek);
        MemberView(member);
    }
}
void EndSeq(EHArray *arr)
{
    Iterator seek;
    Iterator end;
    Member *member = 0;
 
    seek = EHArrayBegin(arr);
    end = EHArrayEnd(arr);
 
    for(   ; seek != end; ++seek)
    {
        member = (Member *)(*seek);
        DeleteMember(member);
    }
    DeleteEHArray(arr);
}
 
EHArray *MakeArray(void);
void InputIndex(EHArray *arr);
void ViewIndex(EHArray *arr);
void EndIndex(EHArray *arr);
void ExampleIndex()
{
    EHArray *arr = 0;
    arr = MakeArray();
    InputIndex(arr);
    ViewIndex(arr);
    EndIndex(arr);
}
 
 
EHArray *MakeArray(void)
{
    int max = 0;
    printf("최대 관리할 회원 수를 입력하세요.\n");
    scanf_s("%d",&max);
    return NewEHArray(max,0);
}
void InputIndex(EHArray *arr)
{
    int i = 0;
    Member *member = 0;
    int max = EHArrayGetCapacity(arr);
    for(i=0; i<max;i++)
    {
        member = MakeMember(i+1);
        EHArraySetAt(arr,i,member);
    }
}

void ViewIndex(EHArray *arr)
{
    int max = 0;
    int i = 0;
    Member *member = 0;
    max = EHArrayGetCapacity(arr);
    for(i=0; i<max;i++)
    {
        member = (Member *)EHArrayGetAt(arr,i);
        MemberView(member);
    }
}
void EndIndex(EHArray *arr)
{
    int max = 0;
    int i = 0;
    Member *member = 0;
 
    max = EHArrayGetCapacity(arr);
 
    for(i=0; i<max;i++)
    {
        member = (Member *)EHArrayGetAt(arr,i);
        DeleteMember(member);
    }
    DeleteEHArray(arr);
}