'table' undeclared (first use this in a function)

Posted by user2318083 on Stack Overflow See other posts from Stack Overflow or by user2318083
Published on 2013-11-13T02:24:21Z Indexed on 2013/11/13 3:53 UTC
Read the original article Hit count: 58

Filed under:
|
|

So I'm not sure why this isn't working, I'm creating a new table and setting it to the variable 'table' Is there something I'm doing wrong?

This is the error I get when trying to run it:

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

My code is as follows:

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

Then this is my create a table in the hash_table file:

struct Table *Table_create(void){
    struct Table *t;
    t = (struct Table*)calloc(1, sizeof(struct Table));
    return t;
}

From the 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;
}

© Stack Overflow or respective owner

Related posts about c

    Related posts about linux