2014-04-16 9 views
0

이 프로젝트의 해시 테이블 데이터 구조를 만들어야하는데 다른 파일에서도 해 봤습니다. 어떤 이유로 프로그램을 컴파일 할 때 해시 테이블의 초기화 함수 (TableCreate();)에 관한 오류가 발생합니다. main 함수에서이 코드 부분을 제거하고 실행하면 잘 작동하지만 해시 테이블에 무언가를 추가하려고하면 segfault가 발생합니다.경고 : 함수의 암시 적 선언 TableCreate

나는 내 해시 테이블 코드 내 해시 테이블 코드가 내가 GCC 컴파일러를 사용하고 우리의 교수

이 당사에 제공 한 해시 테이블 코드의 예를 기반으로하기 때문에이 오류가 함께 할 수 없다 생각합니다.

이 문제를 해결할 수 있도록 도와주세요.

오류 메시지

SRC/sshell.c :
SRC/sshell.c : 34 : 경고 : 함수 âmainâ에서 기능의 암시 적 선언이 âTableCreateâ
SRC/sshell.c : 34 경고 : 할당은 캐스트

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; 
} 
없이 정수의 포인터를 만든다

hash_table.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 

답변

3

경고 1 : 새로운 식별자보고 후 : 함수 이름 Table_create

2 경고하는 동안 당신은 TableCreate를 호출 그 다음에 (, 컴파일러는 가변 인수를 취하여 int를 반환하는 함수라고 가정합니다.

+0

당신의 도움을 위해 Thoh Mohit. – user3539892