任何人都可以指出错误发生的原因吗?错误是"预期"=",";","asm"或__attribute__在"<"之前

kev*_*vin 2 c malloc

我在这里要完成的是一个带有链表的字典.有一个节点指针数组.我试图使用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));

  }
Run Code Online (Sandbox Code Playgroud)

Kei*_*son 6

只允许在函数内部使用语句.

int main(void) {
Run Code Online (Sandbox Code Playgroud)

在for循环之前,和

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

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