Code về Dynamic Array bị lỗi SIGSEGV signal

Chào m.n. Mình có làm 1 bài test trên Hackerrank và nó lỗi hoài k chạy đc @_@.
Nản quá đành phải lên đây hỏi.
Đề bài: https://www.hackerrank.com/challenges/dynamic-array-in-c/problem

int main()
{   
    int count=0;
    int total_number_of_shelves;
    scanf("%d", &total_number_of_shelves);
    
    int total_number_of_queries;
    scanf("%d", &total_number_of_queries);
    
    total_number_of_pages = (int**)malloc(total_number_of_shelves*sizeof(int));
    total_number_of_books = (int*)malloc(total_number_of_shelves*sizeof(int));  
    
    for(int i=1;i<=total_number_of_shelves;i++)
        *(total_number_of_pages+i) = (int*)malloc(total_number_of_shelves * sizeof(int));
    while (total_number_of_queries--) {
        int type_of_query;
        scanf("%d", &type_of_query);
        if (type_of_query == 1) {
            int x, y;
            scanf("%d %d", &x, &y);
                *(*(total_number_of_pages + x) +count) = y;
                 count++;          
                *(total_number_of_books+x)= count;  

Đây là phần code của mình và nó bảo lỗi SIGSEGV signal.
Mong các cao nhân chỉ bảo -_-
Thanks.

Người ta có cú pháp a[i][j] lại không dùng :sigh:

Chắc là quên reset count rồi.

2 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?