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
[51541] 리스트 while문에 배열을 넣으니 Access Violation 발생하는군요.
풍차나라 [freeplan] 955 읽음    2007-12-08 17:52
아래는 ...
리스트에 저장되어 있는 자료들에게 랜덤으로 의사결정 번호를 부여하는 코드 입니다.
랜덤은 그냥 발생시키는게 아니라 ... 리스트의 전체 개수에 맞게 배열을 만든다음 ...
그 배열의 순서를 마구 뒤섞었습니다.

그 다음 ... 배열을 리스트 while 문 안에서 하나하나 꺼내어서 ...
그 배열값에 따라 리스트 각각에 의사결정 번호를 부여하였습니다.

컴파일은 되는데 ... 프로그램에서 실행버튼을 클릭하니깐 ...
Access Violation 이 발생하네요.

도대체 왜 안되는지 ... 엄청난 시간동안 좌절 중 ... ㅜㅜ;;;
답변 부탁 드립니다.


//---------------------------------------------------------------------------------------------
    list = head;
    if (list == NULL)    return false;

    randomize();
    int init_total = list->divn_count();
    int minus_total = init_total;
    int *arr_divn = (int *)malloc(sizeof(int)*init_total);// divn_cnt); //new int arr_divn[sivn_cnt*sizeof(int)];

    for(int i=0 ; i<init_total ; i++) {
        arr_divn[i] = i+1;                //배열에 값을 부여
    }
    int cnt = init_total;
    for(int j=0 ; j<init_total ; j++) {
        int first_id = int(random(init_total) % cnt);
        int second_id = --cnt;

        int first = arr_divn[first_id];            //두개의 배열을 랜덤으로 선정
        int second = arr_divn[second_id];

        arr_divn[first_id] = second;            //두개의 값을 바꿈
        arr_divn[second_id] = first;
    }
    int sect=0;
    while(list)
    {
        //int count = int(list->divn_count());
        //int tmp_id = int(list->rand_num.search(list->id));
        //int sect = probability(count, tmp_id);

        //////////////////////////////////////
        //Case 1.03 : 확률 자체 구현
        //초기 입력수를 기준으로 90-9-1% 구분

        sect = int((arr_divn[minus_total-1] / init_total) * 100);
        minus_total--;

        //--------------------------------------------------------------------//

        if (sect >= 10)    list->decision = DIV_EVENT_1;
        else if (sect > 0 && sect < 10)    list->decision = DIV_EVENT_2;
        else list->decision = DIV_EVENT_3;

        if (sect >=10) list->decision |= DIV_EVENT_4;
        else if (sect > 0 && sect < 10)    list->decision |= DIV_EVENT_5;
        else list->decision |= DIV_EVENT_6;

        list = list->next;
    }

    free(arr_divn);

+ -

관련 글 리스트
51541 리스트 while문에 배열을 넣으니 Access Violation 발생하는군요. 풍차나라 955 2007/12/08
51543     Re:리스트 while문에 배열을 넣으니 Access Violation 발생하는군요. 열씸! 1079 2007/12/08
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.