KAIST

[알림판목록 I] [알림판목록 II] [글목록][이 전][다 음]
[ KAIST ] in KIDS
글 쓴 이(By): guest (collins) <dilbert.prakinf.>
날 짜 (Date): 2001년 3월 16일 금요일 오후 07시 13분 01초
제 목(Title): Re: [Q] C에서 realloc에 관련된 문제.


/*| [0, a], [a+1, 2a], [2a+1, 3a],                                    */
/*| for a given input number n, we could find an interval in which it */ 
/*| can be safely located. find_ceil aways return upper bound         */
int find_ceil(int n, int a)
{
    if (n % a)
        return ((n/a) + 1) * a;
    else
        return n;
}

void main(void)
{
    int room_size = 10; /*| whatever you want could come , but larger */
                        /*| than 1.                                   */
    int m = 0;

    for (t = 0 ; t = call_arr) {

        if (find_ceil(m-1, room_size) < find_ceil(m, room_size))  {
            int new_size = find_ceil(m, room_size);
            chreq = realloc(chreq, new_size * sizeof(CHREQ_PACKET*));
        }

        chreq[m] = malloc(sizeof(CHREQ_PACKET));

        *chreq[m].s_id =s;
        *chreq[m].d_id =d;
        *chreq[m].hop_cnt =0;
        *chreq[m].route_list[0] =s;
        *chreq[m].free_slot_list =never_ask;

        m++;
    }
}

[알림판목록 I] [알림판목록 II] [글 목록][이 전][다 음]
키 즈 는 열 린 사 람 들 의 모 임 입 니 다.