c - 警告 : implicit declaration of function TableCreate

标签 c hashtable compiler-warnings implicit-declaration

我必须为这个项目建立一个哈希表数据结构,我已经在其他文件中完成了。出于某种原因,当我编译我的程序时出现错误,这是关于哈希表的初始化函数 (TableCreate();)。当我从 main 函数中删除这部分代码并执行时,它工作正常,但是当我尝试向哈希表中添加一些内容时出现段错误。

我相信我的哈希表代码与此错误无关,因为我的哈希表代码基于我们教授提供给我们的哈希表代码示例

我正在使用 GCC 编译器。

请帮我解决这个问题。

错误信息

src/sshell.c: In function âmainâ:
src/sshell.c:34: warning: implicit declaration of function âTableCreateâ
src/sshell.c:34: warning: assignment makes pointer from integer without a cast

sshell.c

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



int main(void){

    char input[1000], sInput[1000]; // String to get user input
    int count=1, len; // num=0;





    struct Table *t;
    t = TableCreate(); //create the table




    int while_track;
    FILE *ptr_file;
    ptr_file =fopen(".simpleshell_history","a");
    fclose(ptr_file);
    printf("\nWelcome to the sample shell!  You may enter commands here, one\n");
    printf("per line.  When you're finished, press Ctrl+D on a line by\n");
    printf("itself.  I understand basic commands and arguments separated by\n");
    printf("spaces, redirection with < and >, up to two commands joined\n");
    printf("by a pipe, tilde expansion, and background commands with &.\n\n");

    printf("\npssh$ ");
    while (fgets(input, sizeof(input), stdin)) {
          strcpy(sInput, input);
          len = strlen(input);
          if( input[len-1] == '\n' ){
              input[len-1] = '\0';
          }
          while_track = 1;  // used to keep track of loop
          while (while_track == 1){
                count+=1;
                if (strcmp(input, "history")==0){       
                   while_track = History(); // print history function call
                }else if (strcmp(input, "!!")==0){
                      while_track = Previous(input); // execute previous function call
                }else if (strncmp(input, "!",1)==0){ // !string and !number sort

                      if(isdigit(input[1])){              
                         while_track = Number(input);
                      } else {
                         while_track = String(input);
                      }  

               }else { // if the user entry was not any of specfic comnnad then pass the command to parse to execute
                     other(input,t);
                     parse(input);

                     while_track = 0;
               }     
          }
          HistoryFile(sInput); // A function call to recode commands entered by the user into a file
          printf("\npssh$ ");
    }
    return 0;
}

哈希表.c

#include "hash_table.h"
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>



void feedData(char * var, char * val, struct Table *t){
     //const char * key=0;
     printf("\n In FeedData Function\n");
     Table_add(t, var, val);
     printf("\nInside Feed Function -- Veriable: %s Value: %s\n",var, val);
}

unsigned int hash(const char *x) {
         printf("\n In Hash\n");
         int i;
         unsigned int h = 0U;
         printf("\n In Hash - Before for loop\n");
         for (i=0; x[i]!='\0'; i++)
             printf("\n In Hash - In for loop %d \n", i);
             h = h * 65599 + (unsigned char)x[i];
             printf("\n In Hash - In for loop - after calculation \n");
         unsigned int g;
         g = h % 1024;   
         printf("\n In Hash - In for loop - before return: %u \n",g);     
         return g;
}

struct Table *Table_create(void) {
       printf("\n In Table_create\n");
       struct Table *t;
       t = (struct Table*)calloc(1, sizeof(struct Table));
       return t;
}

void Table_add(struct Table *t, const char *key, char * val){

      printf("\n In Table_add\n");
      struct Node *p = (struct Node*)malloc(sizeof(struct Node));
      int h = hash(key);
      printf("\n In Table_add - after hash key\n");
      //p->key = *key;
      strcpy(p->key,key);
      printf("\n In Table_add - after first key\n");
      strcpy(p->value,val);
      printf("\n In Table_add - after Value\n");
      p->next = t->array[h];
      printf("\n In Table_add - after p->next\n");
      t->array[h] = p;
      printf("\n In Table_add - after t->array[h] = p\n");
}
/*
int Table_search(struct Table *t, const char *key, int *value){
    struct Node *p;
    int h = hash(key);  //---------------------------------------------------------------------
    for (p = t->array[h]; p != NULL; p = p->next)
    if (strcmp(p->key, key) == 0) {
       *value = p->value;
       return 1;
    }
    return 0;
}
*/
/*
void Table_free(struct Table *t) {
     struct Node *p;
     struct Node *nextp;
     int b;
     for (b = 0; b < BUCKET_COUNT; b++)
         for (p = t->array[b]; p != NULL; p = nextp) {
             nextp = p->next;
             free(p);
         }
     free(t);
}
*/

hash_table.h文件代码

    #ifndef HASH_TABLE_H
#define HASH_TABLE_H

struct Table *Table_create(void);
void Table_add(struct Table *t, const char *key, char * val);
unsigned int hash(const char *x);
void feedData(char * var, char * val, struct Table *t);


enum {BUCKET_COUNT = 1024};
struct Node {
       char key[1000];
       char variable[1000];
       char value[1000];
       struct Node *next;
};


struct Table {
       struct Node *array[BUCKET_COUNT];
};


#endif

最佳答案

警告 1:您正在调用 TableCreate,而您的函数名称是 Table_create

警告 2:在查看后跟 ( 的新标识符后,编译器假定它是一个接受可变数量参数并返回 int 的函数。

关于c - 警告 : implicit declaration of function TableCreate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23102295/

相关文章:

c - 在C中使用字符串数组的数组来解析文本文件

c - 将 ARM asm 反编译回 C

hashtable - 关于哈希表的几个问题

c++ - 如何防止警告 C4355 : 'this' : used in base member initializer list

c - 如何计算 0 可以是元素的 int 类型数组中的元素数?

c - fopen() 与 gvim 编辑器不能很好地配合

node.js - 使用 Node.js 记住遍历的 fs 路径

java - 使用哈希表代替数据库系统

c - 为什么在使用带有 %f printf 格式说明符的 float 时,clang 3.8 会发出警告?

CUDA ptxas 警告(入口的堆栈大小)