我希望我能在这里得到一组新的眼睛。我正在做一个作业,这是一个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