Это мой файл makefile: попробуйте
trie: trie.o main.o
gcc trie.o main.o -o trie -std=c11 -g -Wall
trie.o: trie.c trie.h
gcc -c trie.c -o trie.o -std=c11 -g -Wall
main.o: main.c trie.h
gcc -c main.c -o main.o -std=c11 -g -Wall
clean:
rm -f *.o trie
и заголовочный файл
#ifndef TRIE_H
#define TRIE_H
struct node;
typedef struct node node;
//insert a word in a leaf
void insert(char* word, node* leaf);
#endif //TRIE_H
и файл trie.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "trie.h"
struct node {
char* data;
node* child[127];
};
void insert (char* word, node* leaf) {
node* curr = leaf;
for (size_t i = 0; i < strlen(word); i++) {//start from beginning of char to end
if (curr == NULL) {
curr = (node*)malloc(sizeof(node)); // if it's null, creating new node
curr->data = "";
}
curr = curr->child[(int) word[i]];
}
curr->data = word; // set last node stored the word
}
появляется сообщение об ошибке в основном файле
#include <stdio.h>
#include <stdlib.h>
#include "trie.h"
int main() {
node* x = (node*) malloc(sizeof(node));
insert("hi", x);
return 0;
}
и это сообщение об ошибке:
main.c: В функции «main»: main.c:7:35: ошибка: недопустимое применение «sizeof» к неполному типу «node {aka struct node}» node* x = (node*) malloc(sizeof(node ));
есть идеи, почему в моем коде есть ошибка?
struct node
в заголовочный файл. - person Dai   schedule 11.05.2017