Note that there are some explanatory texts on larger screens.

plurals
  1. POFor this selection sort, why is the first number 0 when 0 is never used in my array? (in c)
    primarykey
    data
    text
    <p>This is code called by main to sort an array using selections sort in the C language. I have a file opened in main and put the first ten ints into an array and the 11th into a variable and then a bunch of simple functions are called. The whole thing is repeated three times. For my test file, that last two iterations have the correct printed sort, but the first starts with 0, but I don't have a 0 in my array. It also drops the last int.</p> <p>Thanks in advance for all your help!!</p> <p>Here is my code:</p> <pre><code> void sortme (int arry [], int last_int) { int temp; int smallest_int; int current_int; int target_searcher; int numPrinted; for(current_int = 0; current_int &lt; last_int; current_int++) { smallest_int = current_int; for(target_searcher = current_int + 1; target_searcher &lt;= last_int; target_searcher++) if(arry[target_searcher] &lt; arry[smallest_int]) smallest_int = target_searcher; temp = arry[current_int]; arry[current_int] = arry[smallest_int]; arry[smallest_int] = temp; } //end outter loop numPrinted = 0; printf("\nThe sorted array is: "); for(current_int = 0; current_int &lt; SIZE; current_int++) { printf("%4d", arry[current_int]); if(numPrinted &lt; COUNT) numPrinted++; else { printf("\n"); numPrinted = 0; } } printf("\n"); return; } </code></pre> <p>Here is my output for reference (most of the stuff is commenetd out in main.c):</p> <pre><code>The file opened. Scanned into a[] and target is 33 ARRAY[1] The contents in the array are: 40 32 57 27 67 6 3 89 2 99 The sorted array is: 0 2 3 6 27 32 40 57 67 89 The value searched, 33, was not found. Scanned into a[] and target is 3 ARRAY[2] The contents in the array are: 86 43 89 32 45 12 1 58 98 4 The sorted array is: 1 4 12 32 43 45 58 86 89 98 The value searched, 3, was not found. Scanned into a[] and target is 11 ARRAY[3] The contents in the array are: 1 2 3 4 5 6 7 8 9 10 The sorted array is: 1 2 3 4 5 6 7 8 9 10 The value searched, 11, was not found. Closing the file. The file closed. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload