C ';表';未声明(首先在函数中使用此选项)
所以我不确定这为什么不起作用,我正在创建一个新表,并将其设置为变量“table”,我有什么地方做错了吗 这是我在尝试运行时遇到的错误: src/simpleshell.c:19:3:错误:“table”未声明(此函数首次使用) src/simpleshell.c:19:3:注意:每个未声明的标识符对于它出现在其中的每个函数只报告一次 我的代码如下:C ';表';未声明(首先在函数中使用此选项),c,linux,hashtable,C,Linux,Hashtable,所以我不确定这为什么不起作用,我正在创建一个新表,并将其设置为变量“table”,我有什么地方做错了吗 这是我在尝试运行时遇到的错误: src/simpleshell.c:19:3:错误:“table”未声明(此函数首次使用) src/simpleshell.c:19:3:注意:每个未声明的标识符对于它出现在其中的每个函数只报告一次 我的代码如下: #include "parser.h" #include "hash_table.h" #include &
#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_表.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;
}
#包括“hash_table.h”
#包括“parser.h”
#包括“shell.h”
#包括“variables.h”
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
结构表*表;
无符号整数散列(常量字符*x){
int i;
无符号整数h=0U;
对于(i=0;x[i]!='\0';i++){
h=h*65599+(无符号字符)x[i];
}
返回h%1024;
}
您应该声明表的类型。就是
struct Table *table = Table_create();
谢谢你修复了它,但是在另一个文件中,hash_table.c我也用“struct table*table”声明了它;为什么它在那里没有识别出来?我是不是做错了什么,以至于读不正确?你是说你声明了一个全局struct Table*Table代码>在hash_table.c中?我想我已经弄明白了,我没有在hash_table.h中包含一行,这个特定的行:extern struct table*table;
struct Table *table = Table_create();