c - 'table' 未声明(首先在函数中使用它)

标签 c linux hashtable

所以我不确定为什么这不起作用,我正在创建一个新表并将其设置为变量“table”,我做错了什么吗?

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

src/simpleshell.c:19:3: error: ‘table’ undeclared (first use in this function)

src/simpleshell.c:19:3: note: each undeclared identifier is reported only once for each function it appears in

我的代码如下:

#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;
}

最佳答案

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

struct Table *table = Table_create();

关于c - 'table' 未声明(首先在函数中使用它),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19944075/

相关文章:

c - 如何在 C 中授予完整文件权限

c++ - 从 glutMainLoop() 中调用函数

linux - 我想在 linux 上删除多行文本

regex - Linux sed - 需要帮助来弄清楚为什么模式匹配不起作用

c++ - 尝试使用哈希表(使用链接)作为我的顶点列表来制作图形数据结构

c - 在 C 中查找数组中的 n 个重复数字

c - 未定义的输出(K&R 1.19)

将 uint** 转换为 uint

linux - apt-get、rpm 中的网络安全

android - 如何将嵌套哈希表序列化/反序列化为 JSON?