'表'未声明(首先在函数中使用它)

时间:2013-11-13 02:24:22

标签: c linux hashtable

所以我不确定为什么这不起作用,我正在创建一个新表并将其设置为变量'table'我有什么问题吗?

这是我在尝试运行时遇到的错误:

  

src / simpleshell.c:19:3:错误:'table'unclaclared(首次在此函数中使用)

     

src / simpleshell.c:19:3:注意:每个未声明的标识符仅针对它出现的每个函数报告一次

我的代码如下:

#include "parser.h"
#include "hash_table.h"
#include "variables.h"
#include "shell.h"
#include <stdio.h>

int main(void) {
  char input[MAXINPUTLINE];
  table = Table_create();
  signal_c_init();

  printf("\nhlsh$ ");

  while(fgets(input, sizeof(input), stdin)){
     stripcrlf(input);
     parse(input);
     printf("\nhlsh$ ");
  }
  Table_free(table);
  return 0;
}

然后这是我在hash_table文件中创建一个表:

struct Table *Table_create(void){
    struct Table *t;
    t = (struct Table*)calloc(1, sizeof(struct Table));
    return t;
}

来自hash_table.c:

#include "hash_table.h"
#include "parser.h"
#include "shell.h"
#include "variables.h"
#include <stdio.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
#include <fcntl.h>
#include <limits.h>
#include <signal.h>

struct Table *table;

unsigned int hash(const char *x){
    int i;
    unsigned int h = 0U;
    for (i=0; x[i]!='\0'; i++){
        h = h * 65599 + (unsigned char)x[i];
    }
    return h % 1024;
}

1 个答案:

答案 0 :(得分:3)

您应该声明table的类型。也就是说,

struct Table *table = Table_create();