C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[38344] 제발 이것좀 해결해주세요.. ㅠ.ㅜ
오정이 [] 766 읽음    2004-12-10 22:54
아래 구조체로 되어있는것을 이진파일로 바꿔야 합니다.
이것을 이진 파일로 바꿔야 합니다.... 
제가 실력이 부족해서 도무지 모르겠습니다.
제발 이진파일로 바꿔주세요...ㅠ.ㅜ


#include <stdio.h>
#include <string.h>

#define MAX_MEM    200
#define TRUE    1
#define    FALSE    0
#define ERR        -1

typedef struct {
    int        month;
    char    star[20];
    char    stone[20];
    char    valid;    // 유효유무 : 'Y' 유효, 'N' 무효
} MEMBER;

MEMBER    mt[MAX_MEM];

int        Menu();
void    Insert();
int        Search_Blank();
void    Write(int i, MEMBER a);
int        Search_Name(int a);
void    Search();
void    Delete();
void    Update();

void main() {
    int sel, i;

    // 초기화 : 이름 = ""
    for (i = 0; i < MAX_MEM; ++i) {
        mt[i].month = 0;
        mt[i].valid = 'N';
    }

    while (1) {
        sel = Menu();
        switch (sel) {
            case -1:
                printf("[Error] Not number\n");
                break;
            case 1:
                Insert();
                break;
            case 2:
                Update();
                break;
            case 3:
                Delete();
                break;
            case 4:
                Search();
                break;
            case 0:
                return;
            default:
                printf("[Error] Out of range\n");
        }
    }
}

int Menu() {
    char s[81];
    int sel;

    printf("=============================================\n");
    printf(" [0]종료 [1]입력 [2]수정 [3]삭제 [4]검색(월) \n");
    printf("=============================================\n");
    printf(" 서비스번호 = ");
    gets(s);
    if (sscanf(s, "%d", &sel) != 1)
        return -1;
    else
        return sel;
}

void Insert() {
    MEMBER t;
    int i;
    char s[81];

    printf("<<< Insert program >>>\n");
    while (TRUE) {
        printf("Month : ");
        gets(s);
        if (strlen(s) == 0)
            break;
        if (sscanf(s, "%d", &t.month) != 1) {
           
            printf("[Err] Not munber\n");
            continue;
        }
        if ((t.month < 1 ) || (t.month > 12 )) {
            printf("[Err] Out of range\n");
            continue;
        }
        if (Search_Name(t.month) != ERR) {
            printf("[Msg] Already exist\n");
            continue;
        }
        printf("Star : ");
        gets(t.star);
        printf("Stone : ");
        gets(t.stone);
        i = Search_Blank();
        if (i == ERR) {
            printf("[Error] Memory Full\n");
            break;
        }
        printf("Really? (Y/N) ");
        gets(s);
        if (strcmp(s, "Y") == 0) {
            Write(i, t);
            printf("[Msg] Inserted in location %d\n", i);
        }
    }
}

int Search_Blank() {
    int i;
    for (i = 0; i < MAX_MEM; ++i) {
        if (mt[i].valid == 'N')
            return i;
    }
    return ERR;
}

void Write(int i, MEMBER a) {
    mt[i].month = a.month;
    strcpy(mt[i].star, a.star);
    strcpy(mt[i].stone, a.stone);
    mt[i].valid ='Y';
}

int Search_Name(int a) { //  입력값이 정수 a 이다
    int i;
    for (i = 0; i < MAX_MEM; ++i)
        if ((mt[i].month == a) &&
            (mt[i].valid == 'Y'))
            return i;
    return ERR;
}

void Search() {
    char s[20];
    int i, a;

    printf("<<< Search with month >>>\n");
    while (TRUE) {
        printf("Month for search : ");
        gets(s);
        if (strlen(s) == 0)
            break;
        if (sscanf(s, "%d", &a) != 1) {
            printf("[Msg] Not mumber\n");
            continue;
        }
        i = Search_Name(a);
        if (i == ERR)
            printf("[Msg] Can't find\n");
        else {
            printf("Star : %s\n", mt[i].star);
            printf("Stone : %s\n", mt[i].stone);
        }
    }
}

void Delete() {
    char s[20];
    int i, a;

    printf("<<< Delete with month >>>\n");
    while (TRUE) {
        printf("Month for delete : ");
        gets(s);
        if (strlen(s) == 0)
            break;
        if (sscanf(s, "%d", &a) != 1) {
            printf("[Msg] Not mumber\n");
            continue;
        }
        i = Search_Name(a);
        if (i == ERR)
            printf("[Msg] Can't find\n");
        else {
            printf("Really? (Y/N) ");
            gets(s);
            if (strcmp(s, "Y") == 0) {
                mt[i].valid = 'N';
                printf("[Msg] Deleted in location %d\n", i);
            }
        }
    }

}

void Update() {
    MEMBER t;
    char s[20];
    int i;

    printf("<<< Update with month >>>\n");
    while (TRUE) {
        printf("Month for update : ");
        gets(s);
        if (strlen(s) == 0)
            break;
        if (sscanf(s, "%d", &t.month) != 1) {
            printf("[Msg] Not mumber\n");
            continue;
        }
        i = Search_Name(t.month);
        if (i == ERR)
            printf("[Msg] Can't find\n");
        else {
            printf("Star (%s) : ", mt[i].star);
            gets(t.star);
            printf("Stone (%s) : ", mt[i].stone);
            gets(t.stone);
            printf("Really? (Y/N) ");
            gets(s);
            if (strcmp(s, "Y") == 0) {
                Write(i, t);
                printf("[Msg] Updated in location %d\n", i);
            }
        }
    }
}

+ -

관련 글 리스트
38344 제발 이것좀 해결해주세요.. ㅠ.ㅜ 오정이 766 2004/12/10
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.