ある構造体のポインターを別の構造体のノードに向けようとしています。私は今この10時間立ち往生しています。誰かが私のコードを修正するのを手伝ってもらえますか?でセグメンテーション違反が発生していcurr_users -> playlist = p_playlists;
ます。私はそれを間違って指摘していますか?
struct playlist_ {
int album;
int track_num;
struct playlist_ *next;
};
typedef struct playlist_ playlists;
struct users_ {
int user_ID;
struct playlist_ *playlist;
struct users_ *next;
};
typedef struct users_ users;
int transaction(FILE *transaction_file,album *all_album){
int transaction_id,i;
int album_ID,
account_number,
add_playlist_user,
add_playlist_album,
add_playlist_track;
users *head_users,*curr_users,*p_users,*users_pointer;
playlists *head_playlists,*curr_playlists,*p_playlists,*playlist_pointer;
head_users = NULL;
fscanf(transaction_file,"%d\n",&account_number);
/*Checks for empty list, if true creates the first user*/
if( !(head_users)){
p_users = malloc(sizeof(users ));
p_users -> user_ID = account_number;
head_users = p_users;
head_users -> next = NULL;
users_pointer = head_users;
/*If list is not empty create new user and puts it in front of list*/
}else{
p_users = malloc(sizeof(users));
p_users -> user_ID = account_number;
curr_users = p_users;
curr_users -> next = head_users;
head_users = curr_users;
users_pointer = head_users;
}
/*Create an empty playlist for user and set everything to null*/
p_playlists = malloc(sizeof(playlists *));
curr_playlists = p_playlists;
curr_playlists -> album = 5;
curr_playlists -> track_num = 5;
curr_playlists -> next = NULL;
curr_users -> playlist = p_playlists;
このコードを実行したときに受信したエラーメッセージ:
Program received signal SIGSEGV, Segmentation fault.
0x00011050 in transaction (transaction_file=0xff3675cc, all_album=0x226b0)
at functions.c:94
94 curr_users -> playlist = p_playlists;