我希望我能在這裏得到一組新的眼睛。我正在做一個作業,這是一個Boggle遊戲的開始。基本前提是我們有一個包含96個字符的文本文件,我們的程序將單獨讀入這些字符,並將它們作爲節點添加到線性鏈接列表中,然後將每個項目複製到另一個線性鏈接列表中,該列表將放置每個骰子上有6個字符,總共16個骰子。我已經得到了大部分函數可以正常工作,除了下面的函數,它假定採用全部96個字符的線性鏈表(struct boggleDataNode)並將每個字符複製到第二個線性鏈表(struct boggleDieSideNode)。函數中的第三個參數是被複制的字符的索引。我在下面包含了我的主要功能,以便您可以查看實現。任何洞察力或指導將不勝感激,因爲我目前失去了!C鏈接列表 - Boggle程序
void addBoggleDieSide(struct boggleDataNode *head1, struct boggleDieSideNode *head2, int index)
{
int i = 0;
struct boggleDieSideNode *temp = NULL;
struct boggleDieSideNode *right = NULL;
struct boggleDataNode *helper = NULL;
temp = (struct boggleDieSideNode *)malloc(sizeof(struct boggleDieSideNode));
helper = (struct boggleDataNode *)malloc(sizeof(struct boggleDataNode));
helper = head1;
for(i = 0; i <= index; i++)
{
helper = helper->nextData;
}
strcpy(temp->dieSideData, helper->data);
temp->nextSide = NULL;
if (head2 == NULL)
{
head2 = temp;
}
else
{
right = head2;
while(right->nextSide != NULL)
{
right = right->nextSide;
}
right->nextSide = temp;
}
return;
}
int main()
{
int counter = 0;
int i = 1;
struct boggleDataNode *head1 = NULL;
struct boggleDieSideNode *head2 = NULL;
// Reads in original text file to boggleDataNode linked list
read(&head1);
// Displays boggleDataNode linked list
displayDataFile(head1);
for(i = 1; i <= 16; i++)
{
// Clears die that was just created in loop and starts a new die
head2 = NULL;
for(i = 1; i <= 6; i++)
{
addBoggleDieSide(head1, head2, counter);
counter++;
}
// Displays values on each die
displayDieSide(head2);
}
return 0;
}
您是否收到錯誤或錯誤的輸出? – Ediac