This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Why the link list can not be assignment correctly?

typedef struct
{
        char * SongName;
        unsigned char * SongDir;
        unsigned int SongIndexInGroup;
        unsigned int SongPlaying;
}SongInformation;

typedef struct song_link
{
        SongInformation SongInfo;
        unsigned int SongPLayed;
        struct song_link * next;
}SongList,*pSongList;
const char*  GROUP_MUNO_MP3_Name[GROUP_MUNO_MP3_NUM] = {"2.mp3","3.MP3","4.MP3"};
pSongList CreateList(unsigned char  **SongGroup,unsigned char len)
{

        SongList *head,*newNode, *rail;
        unsigned int i;
        i = sizeof(SongGroup);

        head = (pSongList) malloc(sizeof(SongList));
        rail = head;

        head->SongInfo.SongName = SongGroup[0];
        head->SongInfo.SongIndexInGroup = 0;
        head->SongInfo.SongPlaying = FALSE;
        for(i=1;i<len;i++)
        {
                newNode = (SongList*) malloc(sizeof(SongList));
                newNode->SongInfo.SongName = SongGroup[i];
                newNode->SongInfo.SongIndexInGroup = i;
                newNode->SongInfo.SongPlaying = FALSE;
                rail -> next = newNode;
                rail = newNode;
        }
        rail -> next = NULL;
        return head;
}
CreateList(GROUP_MUNO_MP3_Name,GROUP_MUNO_MP3_NUM);


But when I debug into CreateList,the list member can not be assigned correctly.But this source code is correct in vs2008.So what should i change for keil mdk?

Parents
  • You don't even tell what problem you have...

    By the way - have you made sure you have any memory reserved for a heap, i.e. does malloc() return any pointer?

    And why do you have a struct where the SongDir pointer doesn't get an initial value?

    And why an integer for storing a boolean value?

    And why you you mix char* and unsigned char* for the song names?

    Why the dummy assign of sizeof(SongGroup) pointer to i?

    Is the value of GROUP_MUNO_MP3_NUM 3?

Reply
  • You don't even tell what problem you have...

    By the way - have you made sure you have any memory reserved for a heap, i.e. does malloc() return any pointer?

    And why do you have a struct where the SongDir pointer doesn't get an initial value?

    And why an integer for storing a boolean value?

    And why you you mix char* and unsigned char* for the song names?

    Why the dummy assign of sizeof(SongGroup) pointer to i?

    Is the value of GROUP_MUNO_MP3_NUM 3?

Children
No data