title: C: searching an array and returning multiple values
body: <p>I'm working on a sample from my textbook regarding 2 dimensional arrays. It has the following example that allows the user to input a value, and then it searches the array and returns the location of the element that contains the value, or alerts them if the value doesn't exist. </p>
  
  <p>What I'm wondering, is what if multiple elements contain the user's value? In the code, I added some loops to initialize the 2d array, and multiple elements contain the same value. How would I set up the search that it would return multiple elements as containing the search value?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main() {
  
  int iTwoD[3][3];
  int iFoundAt[2] = {0};
  int x, y;
  int iFound, iValue = 0;
  
  
  //initialize the 2-d array
  for ( x = 0; x&lt;=2; x++) {
  
    for (y=0;y&lt;=2;y++)
      iTwoD[x][y] = (x+y);
  } //end outer loop
  
  //print the 2-d array
  for (x=0; x&lt;=2; x++){
  
    for (y=0;y&lt;=2;y++)
      printf("iTwoD[%d][%d] = %d\n", x, y, iTwoD[x][y]);
  
  }//end outer loop
  
  //Get the user's value to search for
  printf("\nEnter your search value: ");
  scanf("%d", &amp;iValue);
  
  //Search the 2-d array for user's value
  for (x = 0; x&lt;=2; x++) {
    for (y = 0; y&lt;=2; y++) {
      if ( iTwoD[x][y] == iValue) {
        iFound = 1;
        iFoundAt[0] = x;
        iFoundAt[1] = y;
        break;
      } //end if
    } //end inner loop
  } //end outer loop
  
  if (iFound ==1)
    printf("\nFound value in iTwoD[%d][%d]\n", iFoundAt[0], iFoundAt[1]);
  else
    printf("\nValue not found\n");
  
  return 0;
  } //end main
  </code></pre>