Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7740761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:51:45+00:00 2026-06-01T08:51:45+00:00

Please help me. I can’t figure out why I get a core dumped when

  • 0

Please help me. I can’t figure out why I get a core dumped when I run this program. Before returning anything I can print all_albums_p just fine. Why am I getting core dumped?

#include "music_server.h"

struct album_ {
  int num_tracks;
  char **tracks;
  int **playlist_hits;

};
typedef struct album_ album;

album *parse_album(FILE *album_file,int *number_of_albums){

  int number_of_album,number_of_tracks,number_of_charaters;
  int i,j;
  char dummy_space;
  int *p;

  fscanf(album_file,"%d", &number_of_album);

  *number_of_albums = number_of_album;

  album *all_albums_p = (album *)malloc(sizeof(album)*number_of_album);

  for(j=0;j<number_of_album;j++){

    fscanf(album_file,"%d", &all_albums_p[j].num_tracks);

    all_albums_p[j].tracks = calloc(all_albums_p[j].num_tracks,sizeof(char));
    all_albums_p[j].playlist_hits = calloc(all_albums_p[j].num_tracks,sizeof(int));

    /*Line 27*/ for(i=0;i<all_albums_p[j].num_tracks;i++){

      fscanf(album_file,"%d", &number_of_charaters);

      all_albums_p[j].tracks[i] = (char *)calloc(number_of_charaters+1,sizeof(char));
      all_albums_p[j].playlist_hits[i] = (int *)malloc(sizeof(int));
      all_albums_p[j].playlist_hits[i] = 0;
      fscanf(album_file," ",dummy_space);
      fscanf(album_file, "%[^\n]s", all_albums_p[j].tracks[i]);
    }
  }
  return all_albums_p;
}

main(int argc, char *argv[]){

  int i,j;
  int *number_of_albums,*number_of_tracks,a;
  a=0;
  number_of_albums = &a;

  album *all_tracks_ptr;

  album_file = fopen(argv[1],"r");
  transaction_file = fopen(argv[2],"r");

  if((album_file == NULL) || (transaction_file == NULL)){
    printf("Either %s or %s could not be open");
  }else{

    all_tracks_ptr = parse_album(album_file,number_of_albums);


    int number_of_tracks[*number_of_albums];
  }
}

errors:

Bus Error (core dumped)

(gdb) bt
#0  0xff277c9c in _smalloc () from /lib/libc.so.1
#1  0xff277d10 in malloc () from /lib/libc.so.1
#2  0xff263830 in calloc () from /lib/libc.so.1
#3  0x00010dd8 in parse_album (album_file=0xff3675bc,
    number_of_albums=0xffbff894) at functions.c:27
#4  0x00010b80 in main (argc=3, argv=0xffbff90c) at project3.c:19
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:51:47+00:00Added an answer on June 1, 2026 at 8:51 am

    You should allocate sizeof(char*) below instead of sizeof(char)

    all_albums_p[j].tracks = alloc(all_albums_p[j].num_tracks,sizeof(char*));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Still having issues with this problem. Please help if you can. So I am
Please help me. I can't understand why this function, that uses texture memory __global__
can someone please help me. why does this return an error: Dim stuff As
Can anyone please help me to work out how to achieve the following? I
I hope someone can help with this please. I am trying to query an
Please help me out with this. I have this small application to load txt
I asked this question yesterday, looking if more people can help me out. I
Hope you guys can help me out once more before I go nuts. Iv'e
Any body please can please help me, how to center a JFrame on Mac.
java experts can you please help me write detached queries as a part of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.