gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 18:41:45 26 4
gpt4 key购买 nike

所以我不确定为什么这不起作用,我正在创建一个新表并将其设置为变量“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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com