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