title: hashtable In C giving wrong output
body: <p>I have created hashtable to solve one of the problem on hackerearth using java.
  link:<a href="https://www.hackerearth.com/practice/data-structures/hash-tables/basics-of-hash-tables/practice-problems/algorithm/mind-palaces-3/" rel="nofollow">https://www.hackerearth.com/practice/data-structures/hash-tables/basics-of-hash-tables/practice-problems/algorithm/mind-palaces-3/</a>
  My java solution is able to pass all the test cases.
  Now with same logic ,I am creating solution in C.
  But by solution in C does not pass all test cases.
  I am learning C.
  Please help me to find the problem in C code.
  Thanks.
  My Java Code:</p>
  
  <pre><code>package hashtable;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  
  public class MindPalces {
      public static void main(String[] args) throws NumberFormatException,
              IOException {
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  
          String string = br.readLine();
          String strArr[] = string.split(" ");
          int n = Integer.parseInt(strArr[0]);
          int m = Integer.parseInt(strArr[1]);
          SinglyLinkLists hashTable[] = new SinglyLinkLists[337];
  
          long array[][] = new long[n][m];
  
          for (int i = 0; i &lt; n; i++) {
              String string1 = br.readLine();
              String[] innerArr = string1.split(" ");
              for (int j = 0; j &lt; m; j++) {
                  array[i][j] = Long.parseLong((innerArr[j]));
              }
          }
  
          for (int i = 0; i &lt; n; i++) {
              for (int j = 0; j &lt; m; j++) {
                  long data = array[i][j];
                  if (data &lt; 0) {
                      data = data * -1;
                  }
                  int index = Hashs.hashFunction(data);
  
                  if (hashTable[index] == null) {
                      SinglyLinkLists linkList = new SinglyLinkLists();
                      linkList.insertAtEnd(i, j, array[i][j]);
                      hashTable[index] = linkList;
  
                  } else {
                      SinglyLinkLists linkList = hashTable[index];
                      linkList.insertAtEnd(i, j, array[i][j]);
                  }
              }
          }
  
          int q = Integer.parseInt(br.readLine());
          for (int i = 0; i &lt; q; i++) {
              long val = Long.parseLong(br.readLine());
              long val1 = val;
              if (val &lt; 0) {
                  val = val * -1;
              }
              int index = Hashs.hashFunction(val);
  
              if (hashTable[index] == null) {
                  System.out.println("-1" + " " + "-1");
  
              } else {
                  SinglyLinkLists linkList = hashTable[index];
                  NOde list = linkList.getNode(val1);
                  if (null != list) {
                      System.out.println(list.getI1() + " " + list.getJ1());
                  } else {
                      System.out.println("-1" + " " + "-1");
                  }
  
              }
          }
      }
  }
  
  class Hashs {
      public static int hashFunction(long key) {
  
          return (int) (key % 337);
      }
  }
  
  class NOde {
      int i1 = 0;
      int j1 = 0;
      NOde link = null;
      long number = 0;
  
      public NOde() {
  
          link = null;
          i1 = 0;
          j1 = 0;
          number = 0;
      }
  
      public NOde(NOde node, int i1, int j1, long number) {
  
          this.i1 = i1;
          this.j1 = j1;
          link = node;
          this.number = number;
      }
  
      public NOde getLink() {
          return link;
      }
  
      public void setLink(NOde link) {
          this.link = link;
      }
  
      public int getI1() {
          return i1;
      }
  
      public void setI1(int i1) {
          this.i1 = i1;
      }
  
      public int getJ1() {
          return j1;
      }
  
      public void setJ1(int j1) {
          this.j1 = j1;
      }
  
      public long getNumber() {
          return number;
      }
  
      public void setNumber(long number) {
          this.number = number;
      }
  }
  
  class SinglyLinkLists {
  
      NOde start = null;
      NOde end = null;
      int size = 0;
  
      public SinglyLinkLists() {
          start = null;
          end = null;
          size = 0;
  
      }
  
      public void insertAtEnd(int i1, int j1, long number) {
          NOde nptr = new NOde(null, i1, j1, number);
          size++;
          if (start == null) {
  
              start = nptr;
              end = start;
  
          } else {
  
              end.setLink(nptr);
              end = nptr;
          }
      }
  
      // Function to display elements
      public NOde getNode(long val) {
  
          if (start.getNumber() == val) {
  
              return start;
          }
          NOde ptr = start;
          ptr = start.getLink();
          while (null != ptr &amp;&amp; ptr.getLink() != null) {
              if (ptr.getNumber() == val) {
                  return ptr;
              }
              ptr = ptr.getLink();
          }
          if (null != ptr &amp;&amp; ptr.getNumber() == val) {
              return ptr;
          }
          return null;
      }
  }
  </code></pre>
  
  <p>My C Code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  struct Node
  {
      int i1;
      int j1;
      long inputVal;
      struct Node * next;
  };
  
  struct hash
  {
  
      struct Node * head;
  };
  struct hash *hashTable=NULL;
  
  
  struct Node *createNode(int i,int j,long number)
  {
  
      struct Node *list;
      list = (struct Node *) malloc(sizeof(struct Node));
      list-&gt;i1 = i;
      list-&gt;j1 = j;
      list-&gt;inputVal=number;
      list-&gt;next = NULL;
  
      return list;
  };
  
  int main()
  {
      int m=0,n=0;
      scanf("%d%d",&amp;m,&amp;n);
  
      hashTable=(struct hash *)calloc(337,sizeof(struct Node));
  
      for(int i=0; i&lt;n; i++)
      {
          for(int j=0; j&lt;m; j++)
          {
              long data=0;
              long copy=0;
  
              scanf("%ld",&amp;data);
              copy=data;
              if(data&lt;0)
              {
  
                  data=data*-1;
              }
              int index=hashFunction(data);
  
              struct Node *newnode = createNode(i,j,copy);
              struct Node *myNode = hashTable[index].head;
  
              if (!myNode)
              {
                  hashTable[index].head=newnode;
              }
              else
              {
                  newnode-&gt;next=hashTable[index].head;
                  hashTable[index].head=newnode;
  
              }
          }
      }
  
      int q=0;
      scanf("%d",&amp;q);
      for(int i=0; i&lt;q; i++)
      {
          long val=0;
          long copy=0;
          int boolean=0;
          scanf("%ld",&amp;val);
          copy=val;
          if(val&lt;0)
          {
              val=val*-1;
          }
          int index=hashFunction(val);
          struct Node *myNode = hashTable[index].head;
          if(!myNode)
          {
              printf("%d %d\n",-1,-1);
          }
          else
          {
  
  
              while (myNode-&gt;next!= NULL)
              {
                  if (myNode-&gt;inputVal==copy)
                  {
                      boolean=1;
                      printf("%d %d\n",myNode-&gt;i1,myNode-&gt;j1);
                      break;
                  }
                  myNode = myNode-&gt;next;
              }
  
              if(myNode-&gt;inputVal==copy &amp;&amp;!boolean)
              {
                  boolean=1;
                  printf("%d %d\n",myNode-&gt;i1,myNode-&gt;j1);
  
              }
              if(!boolean)
              {
                  printf("%d %d\n",-1,-1);
              }
          }
      }
  
      return 0;
  }
  int hashFunction(long data)
  {
      return (int)(data%337);
  }
  </code></pre>
  
  <p>Sample Input:</p>
  
  <pre><code>5 5
  -993655555 -758584352 -725954642 -696391700 -649643547
  -591473088 -568010221 -432112275 -421496588 -351507172
  -323741602 -232192004 -30134637 -369573 100246476
  156824549 174266331 392354039 601294716 763826005
  768378344 802829330 818988557 992012759 999272829
  10
  156824549
  -758584352
  -993655555
  601294716
  -696391700
  802829330
  -993655555
  -232192004
  392354039
  -568010221
  </code></pre>