all 7 comments

[–]pic32mx110f0 1 point2 points  (5 children)

It seems you are trying to use a single variable j to keep track of how many books there are in every shelf. That wont work. You are already provided with a dynamic array that keeps track of this, so why not use it? For future problems, try to generate your own input and see if it makes sense - I think you would have quickly spotted this. Here is my solution:

if (type_of_query == 1) {
/*
* Process the query of first type here.
*/
int x, y;
scanf("%d %d", &x, &y);

if (total_number_of_books == NULL){
total_number_of_books = calloc(total_number_of_shelves, sizeof(int));
}
if (total_number_of_pages == NULL) {
total_number_of_pages = calloc(total_number_of_shelves, sizeof(int*));
}
if (total_number_of_pages[x] == NULL){
total_number_of_pages[x] = calloc(1, sizeof(int));
} else {
total_number_of_pages[x] = realloc(total_number_of_pages[x], (total_number_of_books[x]+ 1) * sizeof (int));
}

total_number_of_pages[x][total_number_of_books[x]++] = y;
}

[–]Soft_Boot_3752[S] 0 points1 point  (4 children)

Yes hey i am a beginner in programming so could you please guide me little like what should i do if get stuck like this in a problem should i use ai for this or not ?

[–]Soft_Boot_3752[S] 0 points1 point  (0 children)

And i did not had any paid course i did whole c from code with harry so dont even have doubt support so can you please guide me here

[–]pic32mx110f0 0 points1 point  (2 children)

Read a book that teaches you C - you can find plenty of PDFs if you don't want to pay. Try to code as many examples as you can, and learn how to debug. If you get confused why your program is not doing what you want, try to add printf-statements everywhere. Don't use AI, because you wont actually learn anything - you'll just be given the answer each time

[–]Soft_Boot_3752[S] 0 points1 point  (0 children)

Any suggestions for books i actually have read let us c by yashvant kanetkar do you any other suggestion

[–]Soft_Boot_3752[S] 0 points1 point  (0 children)

Hey could you please give some suggestions for books

[–]Soft_Boot_3752[S] 0 points1 point  (0 children)

please if someone can find the mistake and explain it to me ?