title: Function was checked to return value A, but in main, the value was found to be -1
body: <p>The bug seems to be in binarySearch function and the for-loop it is in. I have placed a few printf to check for values. binarySearch supposed to return value: 8, but index variable in for-loop is -1. </p>
  
  <p>I apologise if the formatting looks terrible. Please give me guidance on how to to post nice looking code here.</p>
  
  <p>Thank you so much!</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int binarySearch(char[][7], char[], int, int);
  void deleteAndMoveEntry(char[][7], int, int);
  
  int main() {
    // all the variables
    const int MAXIMUM = 5000;
    char temp[7];
    char symbol[MAXIMUM][7];
    int sizeSymbol = 0, sizeDeleted = 0;
    char toDelete[MAXIMUM][7];
    int i = 0, j;
    int index;
    FILE *in = fopen("stockin.txt", "r");
    FILE *deleted = fopen("stockdel.txt", "r");
    FILE *out = fopen("stockout.txt", "w");
    FILE *errorFile = fopen("error.txt", "w");
  
    while (fscanf(in, "%s\n", temp) == 1 &amp;&amp; i &lt; MAXIMUM) {
      strcpy(symbol[i], temp);
      i++;
      sizeSymbol++;
    }
  
    i = 0;
  
    while (fscanf(deleted, "%s\n", temp) == 1 &amp;&amp; i &lt; MAXIMUM) {
      printf("Hi\n");
      strcpy(toDelete[i], temp);
      i++;
      sizeDeleted++;
    }
    // Should we sort array symbol? To implement later for fun
  
    for (i = 0; i &lt; sizeDeleted; i++) {
      index = binarySearch(symbol, toDelete[i], 0, sizeSymbol);
      printf("%d\n", index);
  
      if (index != -1) {
        deleteAndMoveEntry(symbol, index, sizeSymbol);
        sizeSymbol--;
      } else if (index == -1)
        fprintf(errorFile, "%s\n", toDelete[i]);
    }
  
    for (i = 0; i &lt; sizeSymbol; i++)
      fprintf(out, "%s\n", symbol[i]);
  
    fclose(in);
    fclose(out);
    fclose(deleted);
    fclose(errorFile);
    return 0;
  }
  
  int binarySearch(char symbol[][7], char toFind[], int left, int right) {
    if (right &gt;= left) {
      int mid = left + ((right - left) / 2);
      if (strcmp(toFind, symbol[mid]) == 0) {
        printf("%d\n", mid);
        return mid;
      }
  
      if (strcmp(toFind, symbol[mid]) &lt; 0)
        binarySearch(symbol, toFind, left, mid - 1);
  
      if (strcmp(toFind, symbol[mid]) &gt; 0)
        binarySearch(symbol, toFind, mid + 1, right);
    }
    return -1;
  }
  
  void deleteAndMoveEntry(char symbol[][7], int index, int size) {
    int i;
    for (i = index; i &lt; size - 1; i++) {
      strcpy(symbol[i], symbol[i + 1]);
    }
  
    strcpy(symbol[i + 1], "");
  }
  </code></pre>