我在这里要完成的是一个带有链表的字典.有一个节点指针数组.我试图使用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)
只允许在函数内部使用语句.
加
int main(void) {
Run Code Online (Sandbox Code Playgroud)
在for循环之前,和
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在它之后.或者,如果main在另一个文件中,则定义一些其他函数来包含循环.