title: Reading from file and storing into 2D array in C
body: <p>I have set up 2 2D arrays in my code, one for storing an array of IDs and another for passwords. I am attempting to read from a text file with the format:</p>
  
  <pre><code>    ID1 PASSWORD1
      ID2 PASSWORD2
      ID3 PASSWORD3
      ID4 PASSWORD4
      ID5 PASSWORD5
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #define MAX_RECORDS 100
  #define MAX_INPUT 40
  
  void readFile();
  void inputInit();
  void DBInit();
  void init();
  
  
  FILE *fp;
  
  char **IDArray;
  char **passwordArray;
  
  char *IDInput;
  char *passInput;
  
  int main(){
      init();
      readFile();
  
      return 0;
  }
  
  void readFile(){
      fp = fopen("Database_Table.txt","r");
  
      char line[MAX_INPUT];
      if(fp == NULL){
          perror("Error in opening file");
      }
      else{
          int i;
          while(!feof(fp)){
              fgets(line,sizeof(line),fp);
              sscanf(line,"%s\t%s",IDInput,passInput);
              IDArray[i] = IDInput;
              passwordArray[i] = passInput;
              i++;
          }
      }
      fclose(fp);
  }
  
  void init(){
      DBInit();
      inputInit();
  
  }
  
  void inputInit(){
      IDInput = (char*)malloc(sizeof(char) * MAX_INPUT);
      passInput = (char*)malloc(sizeof(char) * MAX_INPUT);
  }
  
  void DBInit(){
      IDArray = (char**)malloc(sizeof(char*) * MAX_RECORDS);
      passwordArray = (char**)malloc(sizeof(char*) * MAX_RECORDS);
  
      int i,j;
      for(i=0;i&lt;MAX_RECORDS;i++){
          IDArray[i] = (char*)malloc(sizeof(char) * MAX_INPUT);
          passwordArray[i] = (char*)malloc(sizeof(char) * MAX_INPUT);
      }
  }
  </code></pre>
  
  <p>My issue is that, for some reason, I keep getting a segmentation fault when I try to store the IDs and the Passwords. Any help to solve this problem would be much appreciated.</p>