sigsegv error

#include<stdio.h>
#include<stdlib.h>

int main(){
    int no_test_cases,i,j,k,no_rooms,no_times_visited,no_bottles,room,max,index = 0,consumed = 0;
    int *visit_description;
    int **room_description;

    scanf("%d",&no_test_cases);

    for(i=0;i<no_test_cases;i++){
        consumed = 0;
        index = 0;
        scanf("%d %d",&no_rooms,&no_times_visited);

        visit_description = (int *)malloc(no_times_visited*sizeof(int));

        for(j=0;j<no_times_visited;j++){
            scanf("%d",&visit_description[j]);
        }

        room_description = (int **)malloc(no_rooms * sizeof(int *));

        for(j=0;j<no_rooms;j++){
            scanf("%d",&no_bottles);
            room_description[j] = (int *)malloc((no_bottles + 1) * sizeof(int));

            for(k = 0;k<no_bottles;k++){
                scanf("%d",&room_description[j][k]);
            }
            room_description[j][k] = -1;
        }

        for(j = 0;j<no_times_visited;j++){
            k = 0;
            room = visit_description[j];
            max = room_description[room][0];

            while(room_description[room][k] != -1){
                if(room_description[room][k] > max){
                    max = room_description[room][k];
                    index = k;
                }
                k++;
            }
            room_description[room][index] = 0;
            consumed = consumed + max;
        }
        printf("%d\n",consumed);
    }
}

i am getting sigsegv error in this coe when i am submitting it on codechef can anyone one help please

take care of array bounds…

sometimes you try to access the invalid index which mainly creates this problem…
also learn it from FAQ

Hi Akash, you can get some help here: http://discuss.codechef.com/questions/7589/why-do-i-get-a-sigsegv

i recommand using static allocation, not dynamic one. bounds are faster to check, and there is no surprise : if it takes to much memory, you’ll see it from the first run. :slight_smile: