title: C - Pointer to index number in an array
body: <p>I know I have to be overlooking something simple. I have a program that lets the user observe how different search algorithms probe arrays by displaying the indexes of each probe. I have a pointer that is passed to the sorting algorithm function, and it should be assigned the index number that the searched number was found at. The pointer is then used in another function to display which index the value was found in (if found).</p>
  
  <p>I get an run-time error in the function that displays the index the value was found in. (<code>search_results</code>) (The program runs fine when the searched number is not in the array.) It has to be a simple mistake, but I think a fresh set of eyes could help.</p>
  
  <p>everything is an <code>int</code>, except <code>found_status</code> which is a <code>char</code></p>
  
  <p>Here is the main() code. (The necessary stuff)</p>
  
  <pre><code>    int *p_return_index = NULL;
  
  /* Fill arrays with data                                           */
  fill_array(seq_data, max_index);
  fill_array(prob_data, max_index);
  fill_array(bin_data, max_index);
  
  while(printf("\n\n\nEnter an integer search target (0 to quit): "),
          scanf("%d", &amp;searched_number), searched_number != 0)
  {
      printf("\n\n");
      printf("\nOrdered Sequential Search:");
      show_data(seq_data, max_index, searched_number);
      if(ordered_seq_search(seq_data, max_index, searched_number, p_return_index) == 1)
      {
          found_status = 'S';
          search_results(found_status, p_return_index);
      }
      else
      {
          found_status = 'U';
          search_results(found_status, p_return_index);
      }
  </code></pre>
  
  <p>This is where the pointer is passed to an assigned the index.</p>
  
  <pre><code>int ordered_seq_search(int array[], int max_index, int searched_number, int *p_return_index)
  {
  int index = 0;
  
  printf("\n   Search Path: ");
  while (index &lt; max_index &amp;&amp; searched_number != array[index] &amp;&amp;
           searched_number &gt; array[index])
  {
      printf("[%2d]", index);
      index++;
  }
  
  if(searched_number == array[index] != 0)
  {
      p_return_index = &amp;index;
      return 1;
  }
  else
      return 0;
  }
  </code></pre>
  
  <p>And this is where the error is happening. </p>
  
  <pre><code>void search_results(char found, int *p_return_index)
  {
  printf("\nSearch Outcome: ");
  if(found == 'S')
      printf("Successful - target found at index [%2d]", *p_return_index);
              //I get the error at the line above.
  if(found == 'U')
      printf("Unsuccessful - target not found");
  if(found != 'S' &amp;&amp; found != 'U')
      printf("Undetermined");
  return;
  }
  </code></pre>
  
  <p>If someone can find out what is wrong, it would be a big help to me. If you need more information just comment, and I'll reply as soon as possible.</p>