gpt4 book ai didi

谁能指出为什么会发生错误?错误是 "expected "=",";","asm"or __attribute__ before "<"

转载 作者:行者123 更新时间:2023-12-04 09:32:04 24 4
gpt4 key购买 nike

我在这里试图完成的是一个带有链表的字典。有一个节点指针数组。我正在尝试使用 malloc 初始化每个数组指针。当我删除 for 循环时,它工作正常。

#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

#include "dictionary.h"

unsigned int count = 0;
unsigned int collisions = 0;
unsigned long index = 0;
#define HASHTABLE_SIZE 1999099

// Initialize struct for linked list.

typedef struct node{
char word[46];
struct node *next;
} node;

// Initialize an array of node pointers.

node *hashtable[HASHTABLE_SIZE];


for(unsigned long i = 0; i < HASHTABLE_SIZE; i++)
// Error here reads expected "=",";","asm" or __attribute__ before "<"

{
hashtable[i] = (node *)malloc(sizeof(node));

}

最佳答案

只能在函数内部使用语句。

添加

int main(void) {

在 for 循环之前,以及

    return 0;
}

在它之后。或者,如果 main 在另一个文件中,定义一些其他函数来包含循环。

关于谁能指出为什么会发生错误?错误是 "expected "=",";","asm"or __attribute__ before "<",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8901897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com