0
背景:我在一个名为hash_table.c的文件中创建了一个Hashtable。这里是什么我的头文件hash_table.h包含部分:检查结构是否存在? [C]
/* hash_table.h */
#ifndef HASH_TABLE_H
#define HASH_TABLE_H
enum {BUCKET_COUNT = 1024};
struct Node {
char *key;
char *value;
struct Node *next;
};
struct Table {
struct Node *array[BUCKET_COUNT];
};
struct Table *TableCreate(void); //creates the table
....
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ 我想在一个名为fdata.c的不同C文件中启动Hashtable。我不知道该怎么办最好的方法是但这里是我的想法是:
#include "hash_table.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Table *t; //initiate the variable
void testFunc()
{
if(Hashtable does not exist) { //How do I accomplish this? Is it possible?
t = TableCreate(); //create the table
else{
continue...
....
显然,如果有更好的方法来启动这个表,我所有的耳朵。 (这是我第一次用C结构)
感谢您的支持!
使用NULL和nil有什么区别,因为nil在NULL似乎正在工作时给我一个错误。 – 2013-05-06 00:11:01
意义没有太大的区别。目标C使用零,常规的C使用NULL。他们都意味着零。 – StilesCrisis 2013-05-06 01:41:50
'nil'用于对象,'NULL'用于非对象!看到[这个SO答案](http://stackoverflow.com/questions/557582/null-vs-nil-in-objective-c) – HAS 2013-05-06 07:34:31